我想更新RecylerView的特定位置的視圖,但它不會發生,由於一些問題如下 - 1)當向上/向下滾動它創建混亂 2)我通過holder.setIsRecyclable(false);
來處理這個問題,但是當向上/向下滾動時,它再次不顯示先前保存的子狀態。更新回收查看活動的startOnActivityResult特定位置
我的代碼如下 -
適配器類
public class EventNameAdapter extends RecyclerView.Adapter<EventNameAdapter.MyViewHolder> {
private List<EventNameModel> eventNameList;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView eventNameText;
public ImageView imageViewRadio;
public MyViewHolder(View view) {
super(view);
eventNameText = (TextView) view.findViewById(R.id.eventNameText);
imageViewRadio = (ImageView) view.findViewById(R.id.imageViewRadio);
}
}
public EventNameAdapter(List<EventNameModel> eventNameList) {
this.eventNameList = eventNameList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.event_name, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
EventNameModel movie = eventNameList.get(position);
holder.setIsRecyclable(false);
holder.eventNameText.setText(movie.getEventName());
}
@Override
public int getItemCount() {
return eventNameList.size();
}
}
UPDATE位置代碼
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101) {
if(resultCode == RESULT_OK){
int responseInt = data.getIntExtra("SUBMIT_DATA",-2);
Toast.makeText(EventListActivity.this,"Response- "+responseInt,Toast.LENGTH_SHORT).show();
if(responseInt>=0){
EventNameAdapter.MyViewHolder viewHolder = (EventNameAdapter.MyViewHolder) nameRecyclerView.findViewHolderForAdapterPosition(responseInt);
if (viewHolder != null) {
Toast.makeText(EventListActivity.this,"Response 2 - "+responseInt,Toast.LENGTH_SHORT).show();
viewHolder.imageViewRadio.setImageResource(R.drawable.radio_button_on);
Log.d("hellotom", "if i=" + responseInt);
} else {
Log.d("hellotom", "else i=" + responseInt);
}
}
}
}
}
請幫助我,我將如何解決這個問題。
如何通過recyclerview適配器更新,而不是直接編輯viewholder自己呢? –
我想只更新特定位置的孩子,但它取決於以前活動的回答 –