I was already looking for various navigation solutions but I couldn't fit any for my app.
I have Parcelable objecs which are displayed in ListView using Array Adapter. When i click on item, it goes to another activity with another layout, dedicated to display this single item with image gallery, title etc. Therefore, i would like to add simple navigation as in picture which moves to next item if exist, previous item if exist and back to List View.
Here's some code
Single Item activity
public class SingleItem extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_item);
Intent intent = getIntent();
Single singleItem = intent.getParcelableExtra("Single");
String id = singleItem.getId();
Integer position = singleItem.getPosition();
String title = singleItem.getTitle();
String subtitle = singleItem.getSubtitle();
String text = singleItem.getText();
int[] image = singleItem.getImage();
TextView titleTV = findViewById(R.id.singleItemTitle);
LinearLayout gallery = findViewById(R.id.gallery);
LayoutInflater inflater = LayoutInflater.from(this);
for (int i = 0; i < image.length; i++) {
View view = inflater.inflate(R.layout.single_item_gallery, gallery, false);
ImageView imageView = view.findViewById(R.id.singleItemGalleryImage);
imageView.setImageResource(image[i]);
gallery.addView(view);
}
TextView descTV = findViewById(R.id.singleItemDesc);
titleTV.setText(title);
descTV.setText(text);
}
}
Here's my adapter
val listViewAdapter = ItemListAdapter(this, R.layout.adapter_view_layout, itemList)
listView.adapter = listViewAdapter
listView.setOnItemClickListener { _: AdapterView<*>, _: View, position : Int, _: Long ->
val intent = Intent(this, SingleItem::class.java)
intent.putExtra("Single", itemList[position])
startActivity(intent)
}
Single Item layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/singleItemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/singleItemTitle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="220dp"
android:paddingStart="10dp"
android:scrollbars="none"
android:paddingEnd="10dp">
<LinearLayout
android:id="@+id/gallery"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"/>
</HorizontalScrollView>
<TextView
android:id="@+id/singleItemDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
And i would like put navigation in layout above.
List view:
Single item navigation example:

