我正在使用列表数组填充我的回收站视图。我已经试过字符串数组,因为它不适合我。我做这一切都错了,或者我必须使用arrayadapter?使用ListArray填充RecyclerView
如果我不得不去阵列适配器我怎么能做到这一点?我已经用arrayadapter填充了listview,但是因为我在海洋中间,我不想尝试一些大的东西。我的recyclerview适配器的代码如下。
它不显示错误。但视图正在填充数组上的最后一个项目。
public class AudioRecycleViewAdapter extends
RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<String> values = Arrays.asList ("Al Feel","Al Humazah","Al
Kausar","Al Maoon","Al Quresh","Dr Israr",
"Al Kafiroon","An Nasr","Al Lahab","Al Ikhlaas","Al Falaq","An
Naas","Iman Part 1",
"Iman Part 2","Iman Part 3","Iman Part 4","Iman Part 5");
Context context;
InterstitialAd mInterstitialAd;
private int audiolayout;
public TextView txtHeader;
public TextView txtFooter;
TextView txtarabic;
public AudioRecycleViewAdapter(List<String> values, int audiolayout, Context context, InterstitialAd intAdView) throws IOException {
this.audiolayout = audiolayout;
this.context = context;
this.mInterstitialAd = intAdView;
}
public Context getContext() {
context = this.getContext();
return context;
}
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public View layout;
public ViewHolder(View v) {
super(v);
layout = v;
txtHeader = (TextView) v.findViewById(R.id.audio_subtitle);
txtFooter = (TextView) v.findViewById(R.id.audio_title);
txtarabic = (TextView) v.findViewById(R.id.arabic_title);
}
}
public void add(int position, String item) {
values.add(position, item);
notifyItemInserted(position);
}
public void remove(int position) {
values.remove(position);
notifyItemRemoved(position);
}
// Create new views (invoked by the layout manager)
@Override
public AudioRecycleViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
LayoutInflater inflater = LayoutInflater.from(
parent.getContext());
View v =
inflater.inflate(R.layout.audio_row_layout, parent, false);
// set the view's size, margins, paddings and layout parameters
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int x;
for(position =0; position < values.size(); position++)
{
txtHeader.setText(values.get(position));
position++;
}
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return values.size();
}
}
你能分享你的错误日志吗? – R2R
不显示错误...它填充列表上的最后一个项目在每一行 –