-2

I used Gridview. It has 58 items. For example when i enter to 48th item and press back button gridview goes to 1st item. I want to say goes up to top. After i again have use scroll to go down items. I mean how to make gridview when press back button stay there where entered. For example i go to 50th item and when press back i have to be at 50th item and easily go down items. Thanks very much for answers.

Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="namangan.nisd.uz.rusuzbeksozlashgich.MainActivity">

<GridView
android:id="@+id/gridView"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:horizontalSpacing="@dimen/grid_view_horizontal_spacing"
android:listSelector="@android:color/transparent"
android:numColumns="@integer/grid_columns"
android:paddingLeft="@dimen/grid_view_padding_edge"
android:paddingRight="@dimen/grid_view_padding_edge"
android:scrollbars="none"
android:verticalSpacing="@dimen/grid_view_vertical_spacing"
android:layout_above="@+id/adViewRusAsosiy"
android:layout_alignParentTop="true" />

</RelativeLayout>

Code:

private GridView gridView;
...
this.gridView = ((GridView)findViewById(R.id.gridView));
this.gridView.setNumColumns(3);
this.gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
Mehmet K
  • 2,719
  • 1
  • 19
  • 34

1 Answers1

0

in your adapter function onBindViewHolder use as

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             //do you logic   
            }
        });

remember use your custom adapter

Nisar Ahmad
  • 150
  • 1
  • 6