そのため、ParseQuery アダプターからデータを取得する recyclerview アダプターを使用しています。とにかく、今の問題は、各項目または行にボタンがあることです。投票ボタンのように。
1 つのボタンをクリックするたびに、他の行の他のボタンが自動的にランダムにクリックされます。
問題は何ですか?
これが私のコードです。
public class RVAdapter extends RecyclerView.Adapter<RVAdapter.ViewHolder> {
private ViewGroup parseParent;
private Context context;
public Button voteUp;
private RVAdapter recyclerAdapter = this;
private ParseQueryAdapter<ParseObject> parseAdapter;
public RVAdapter(Context context, ViewGroup parentIn) {
super();
this.context = context;
// performance optimization for recycler view
setHasStableIds(false);
parseParent = parentIn;
parseAdapter = new ParseQueryAdapter<ParseObject>(context, getImagesQueryFactory()) {
@Override
public View getItemView(ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
}
super.getItemView(object, v, parent);
final ParseImageView Image = (ParseImageView) v.findViewById(R.id.list_item_image);
final ParseFile imageFile = object.getParseFile("img");
if (imageFile != null) {
//Get singleton instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
//Load the image from the url into the ImageView.
imageLoader.displayImage(imageFile.getUrl(), audioImage);
}//end if
voteUp= (Button) v.findViewById(R.id.like);
voteUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
voteUp.setEnabled(false);
voteUp.setText("voted Up");
}
});
return v;
}
};//end parseAdapter
loadImages();
parseAdapter.addOnQueryLoadListener(new OnQueryLoadListener());
parseAdapter.loadObjects();
} //end of RVAdapter
private ParseQueryAdapter.QueryFactory<ParseObject> getImagesQueryFactory() {
return new ParseQueryAdapter.QueryFactory<ParseObject>() {
//Query details.....
return query;
}
};
}
public void loadImages() {
ParseQuery<ParseObject> query = ParseObject.getQuery();
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, com.parse.ParseException e) {
if (e == null) {
notifyDataSetChanged();
} else {
//error
}
}
});
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
parseAdapter.getView(position, holder.itemView, parseParent);
}
@Override
public int getItemCount() {
return parseAdapter.getCount();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ViewHolder(View itemView) {
super(itemView);
});
}
}
public class OnQueryLoadListener implements ParseQueryAdapter.OnQueryLoadListener<ParseObject> {
public void onLoading() {
}
public void onLoaded(List<ParseObject> objects, Exception e) {
recyclerAdapter.notifyDataSetChanged();
}
}
}