私は配列リストの項目を表示するには、RecyclerView
を構築していますが、私は、クリックリスナーに作らんが、私はそこから私のビューを更新カントonClick
メソッドを実装する場合|。そしてここに私のRecyclerView
アダプタアンドロイドリサイクラービュー・アダプタ
public class FeedRecyclerAdapter extends RecyclerView.Adapter<FeedRecyclerAdapter.ViewHolder> {
public static ArrayList<FeedObject> feedObjectArrayList;
@Override
public FeedRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.feeditemlayout, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
v.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
return viewHolder;
}
@Override
public void onBindViewHolder(final FeedRecyclerAdapter.ViewHolder holder, int position) {
final FeedObject feedObject = feedObjectArrayList.get(position);
holder.likeFeedItemTV.setText(feedObject.getNumAgree() + "");
holder.dislikeFeedItemTV.setText(feedObject.getNumDisAgree() + "");
holder.commentFeedItemTV.setText(feedObject.getNumComments() + "");
holder.mediaFeedItemTV.setText(feedObject.getMediaSize() + "");
}
@Override
public int getItemCount() {
return feedObjectArrayList.size();
}
public FeedRecyclerAdapter(ArrayList<FeedObject> feedObjectArrayList) {
this.feedObjectArrayList = feedObjectArrayList;
}
public static class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
private ImageView likeFeedItem, profileImageView, likeFeedItemIV, dislikeFeedItem, commentFeedItem, mediaFeedItem;
private TextView personName, personDetails, cat_Info_Feed_Item, descriptionFeedItemTV, likeFeedItemTV, dislikeFeedItemTV, commentFeedItemTV, mediaFeedItemTV, agreeFeed, disagreeFeed, commentFeed, mediaFeed;
private ImageButton moreOption;
private Button seeMore;
public ViewHolder(View itemView) {
super(itemView);
likeFeedItemTV = (TextView) itemView.findViewById(R.id.likeFeedItemTV);
dislikeFeedItemTV = (TextView) itemView.findViewById(R.id.dislikeFeedItemTV);
commentFeedItemTV = (TextView) itemView.findViewById(R.id.commnetFeedItemTV);
mediaFeedItemTV = (TextView) itemView.findViewById(R.id.mediaFeedItemTV);
likeFeedItem = (ImageView) itemView.findViewById(likeFeedItemIB);
dislikeFeedItem = (ImageView) itemView.findViewById(dislikeFeedItemIV);
commentFeedItem = (ImageView) itemView.findViewById(commentFeedItemIV);
mediaFeedItem = (ImageView) itemView.findViewById(mediaFeedItemIV);
agreeFeed = (TextView) itemView.findViewById(agreeFeedTV);
disagreeFeed = (TextView) itemView.findViewById(disagreeFeedTV);
commentFeed = (TextView) itemView.findViewById(commentFeedTV);
mediaFeed = (TextView) itemView.findViewById(commentFeedTV);
likeFeedItem.setOnClickListener(this);
dislikeFeedItem.setOnClickListener(this);
commentFeedItem.setOnClickListener(this);
mediaFeedItem.setOnClickListener(this);
agreeFeed.setOnClickListener(this);
disagreeFeed.setOnClickListener(this);
commentFeed.setOnClickListener(this);
mediaFeed.setOnClickListener(this);
seeMore = (Button) itemView.findViewById(seeMoreFeedItemTV);
moreOption = (ImageButton) itemView.findViewById(moreFeedItemIB);
seeMore.setOnClickListener(this);
moreOption.setOnClickListener(this);
itemView.setOnClickListener(this);
}
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
default:
return false;
}
}
@Override
public void onClick(View v) {
final FeedObject feedObject = feedObjectArrayList.get(getAdapterPosition());
switch (v.getId()) {
case moreFeedItemIB:
PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
MenuInflater menuInflater = popupMenu.getMenuInflater();
menuInflater.inflate(R.menu.feeditemmenu, popupMenu.getMenu());
popupMenu.show();
break;
case likeFeedItemIB:
case agreeFeedTV:
new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
Boolean b=feedObject.isAgree();
if (b != null) {
if (b) {
feedObject.setAgree(null);
feedObject.setNumAgree(feedObject.getNumAgree() - 1);
} else {
feedObject.setAgree(true);
feedObject.setNumAgree(feedObject.getNumAgree() + 1);
feedObject.setNumDisAgree(feedObject.getNumDisAgree() - 1);
}
} else {
feedObject.setAgree(true);
feedObject.setNumAgree(feedObject.getNumAgree() + 1);
}
return null;
}
}.execute();
//here is my problem i can't update my view
break;
case dislikeFeedItemIV:
case disagreeFeedTV:
new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
Boolean c=feedObject.isAgree();
if (c != null) {
if (c) {
feedObject.setAgree(false);
feedObject.setNumAgree(feedObject.getNumAgree() - 1);
feedObject.setNumDisAgree(feedObject.getNumDisAgree()+ 1);
} else {
feedObject.setAgree(null);
feedObject.setNumAgree(feedObject.getNumAgree() - 1);
}
} else {
feedObject.setAgree(false);
feedObject.setNumDisAgree(feedObject.getNumDisAgree() + 1);
}
return null;
}
}.execute();
break;
case seeMoreFeedItemTV:
case commentFeedItemIV:
case commentFeedTV:
v.getContext().startActivity(new Intent(v.getContext(),DetailedFeed.class));
break;
case mediaFeedItemIV:
case mediaFeedTV:
break;
}
}
}
}
'onBindViewHolder'メソッドで' onClick'リスナーを設定してみてください。 –