我有RecyclerView
填充ListView
。在每個ListView
有一個Button
,它增加了列表。如何更改按鈕圖像像切換按鈕RecyclerView按鈕以編程方式點擊
這裏如果沒有按它
這裏是被按下時,該按鈕的外觀按鈕的外觀,
我該如何保留but噸每個ListView
恭敬地按?
這是我的適配器
public class BuildCustomAdapter extends RecyclerView.Adapter<BuildCustomAdapter.MyViewHolder> implements Filterable {
private int previousTotal = 0;
private boolean loading = true;
private List<Build> buildList;
private List<Build> buildListCopy;
private ItemFilter mFilter = new ItemFilter();
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.build_list_row, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Build build = buildList.get(position);
holder.imageView.setImageResource(build.getImages());
holder.name.setText(build.getName());
}
@Override
public int getItemCount() {
return buildList.size();
}
@Override
public Filter getFilter() {
if (mFilter == null) {
mFilter = new ItemFilter();
}
return mFilter;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public ImageView imageView;
public TextView name;
public Button button;
public MyViewHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.ivPerson);
name = (TextView) itemView.findViewById(R.id.tvPersonName);
button = (Button) itemView.findViewById(R.id.addbn);
}
}
private class ItemFilter extends Filter {
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (constraint != null && constraint.length() > 0) {
List<Build> filterList = new ArrayList<Build>();
for (int i = 0; i < buildList.size(); i++) {
if ((buildList.get(i).getName().toUpperCase())
.contains(constraint.toString().toUpperCase())) {
Build builddata = new Build(buildList.get(i).getImages(), buildList.get(i).getName());
filterList.add(builddata);
}
}
results.count = filterList.size();
results.values = filterList;
} else {
results.count = buildList.size();
results.values = buildList;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
buildList = (ArrayList<Build>) results.values;
notifyDataSetChanged();
}
}
public BuildCustomAdapter(List<Build> buildList) {
this.buildList = buildList;
}
}
Build.class
public class Build {
private String name;
private int images;
public Build(int images, String name) {
this.images = images;
this.name = name;
}
public int getImages() {
return images;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
經過這段代碼,你不需要使用'''build = new Build(R.drawable.ak,「Aksahy Kumar」);''' –
嗨Abdul Rizwan在我的情況下我沒有把' public build布爾選擇,字符串名稱){ //this.images = images; this.selected =選中; this.name = name; }'在活動類'build = new Build(R.drawable.ak,「Aksahy Kumar」); buildList.add(build);' – Joy
我已更新我的代碼。只是看看。 –