古詩詞大全網 - 成語解釋 - android recyclerview 加載數據過多會奔潰嗎

android recyclerview 加載數據過多會奔潰嗎

item數量超過6條就會出現item重復,亂序

代碼如下

fragment布局

<LinearLayout xmlns:android="/apk/res/android"

xmlns:tools="/tools"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

tools:context="invinciblejoe.com.lightingbuy.main.LightingFragment">

<android.support.v7.widget.RecyclerView

android:id="@+id/commodity_list"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

</LinearLayout>

recyclerview item布局

<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.CardView

xmlns:android="/apk/res/android"

xmlns:app="/apk/invinciblejoe.com.lightingbuy"

android:layout_width="match_parent"

android:layout_height="150dp"

android:layout_marginTop="10dp"

android:layout_marginBottom="10dp"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"

app:cardBackgroundColor="@color/orange"

app:cardCornerRadius="20dp">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TextView

android:id="@+id/pic"

android:layout_width="match_parent"

android:layout_height="120dp"

android:gravity="center"

android:textSize="50sp"

/>

<TextView

android:clickable="true"

android:id="@+id/name"

android:layout_width="match_parent"

android:layout_height="60dp"

android:background="@color/orange"

android:textColor="@android:color/white" />

</LinearLayout></android.support.v7.widget.CardView>

recycerview adapter

public class LightingRVAdapter extends RecyclerView.Adapter { private List<Commodity> mlist; private Context mContext; private LightingViewHolder viewHolder; public LightingRVAdapter(Context mContext, List<Commodity> mlist) { this.mContext = mContext; this.mlist = mlist;

} @Override

public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_lighting, parent, false);

viewHolder = new LightingViewHolder(v); return viewHolder;

} @Override

public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

Commodity c = mlist.get(position);

viewHolder.mImageView.setText(c.getName());

viewHolder.mTextView.setText(String.valueOf(c.getPrice_discont()));

} @Override

public int getItemCount() { return mlist == null ? 0 : mlist.size();

} private class LightingViewHolder extends RecyclerView.ViewHolder

implements View.OnClickListener

{ public TextView mTextView; public TextView mImageView; public LightingViewHolder(View v )

{ super(v);

mTextView = (TextView) v.findViewById(R.id.name);

mImageView = (TextView) v.findViewById(R.id.pic);

mImageView.setOnClickListener(this);

} @Override

public void onClick(View view) { switch (view.getId()) { case R.id.pic :

mTextView.setText("OnChlic"); break;

}

}

}

}