我使用了Gridview。它有58项。例如,当我输入第48项并按后退按钮时,gridview转到第1项。我想说到顶部。我再次使用滚动下去项目。我的意思是当按下后退按钮停留在输入的位置时如何制作gridview。例如,我去第50项,当按回来时,我必须在第50项,并轻松下去项目。非常感谢您的回答。
布局:
<?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>
代码:
private GridView gridView;
...
this.gridView = ((GridView)findViewById(R.id.gridView));
this.gridView.setNumColumns(3);
this.gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
答案 0 :(得分:0)
onBindViewHolder用作
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do you logic
}
});
请记住使用自定义适配器