當gridview滾動時,不正確。當它滾動時,最後的項目首先出現。最後一個項目和第一個項目被覆蓋。我之前使用過gridview,但它第一次來。這是爲什麼發生?Gridview不能正確滾動
public class GridViewAdapter extends BaseAdapter {
private static LayoutInflater mInflater;
private View mView;
private int mPosition;
private ViewGroup mParent;
private Context mContext;
private ArrayList<String> mTexts = new ArrayList<>();
public GridViewAdapter(Context context, ArrayList<String> texts){
mContext = context;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mTexts = texts;
}
@Override
public int getCount() {
return mTexts.size();
}
@Override
public Object getItem(int position) {
return mTexts.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
mView = mInflater.inflate(R.layout.items, parent, false);
mPosition = position;
mParent = parent;
setCategoryName(position);
setAmount();
}
return mView;
}
private void setAmount(){
TextView amount = (TextView) mView.findViewById(R.id.amount);
}
private void setCategoryName(int position){
TextView categoryName = (TextView) mView.findViewById(R.id.category_name);
categoryName.setText(mTexts.get(position));
}
}
items.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- Amount -->
<TextView
android:id="@+id/amount"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:gravity="center"
android:background="@drawable/shape_category"
android:text="40"
android:textSize="20dp"
/>
<!-- Category Name -->
<TextView
android:id="@+id/category_name"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:gravity="center"
/>
<!-- Edit category -->
<FrameLayout
android:id="@+id/frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
>
</FrameLayout>
顯示適配器代碼 – Sanoop
你在GridView中顯示? itemview中有沒有可點擊的內容? –
我沒有使用任何可點擊的視圖,我編輯items.xml – nocmmnt