![](/img/trans.png)
[英]How to pass/get value checkbox from adapter recycleview to another activity
[英]Get value from Activity to custom array adapter
我正在创建聊天应用程序。 所以我想增加用户从他的朋友那里得到的消息数量。 为了表明我创建了自定义Array adapter
是因为我的列表视图由朋友名称和notification textview
。
因此,我的list_of_registerd_users活动中包含数据:
如何将这些数据发送到自定义array adapter
类以设置通知视图:
自定义数组适配器类 :
public class CustomArrayAdapter extends ArrayAdapter<String> {
private Context mContext;
private int mRes;
private ArrayList<String> data;
private String numOfMsgs;
public CustomArrayAdapter(Context context, int resource,
ArrayList<String> objects) {
super(context, resource, objects);
this.mContext = context;
this.mRes = resource;
this.data = objects;
}
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return super.getItem(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater inflater = LayoutInflater.from(mContext);
row = inflater.inflate(mRes, parent, false);
String currentUser = getItem(position);
TextView friendName = (TextView) row.findViewById(R.id.tvFriendName);
String Frndname = currentUser;
friendName.setText(Frndname);
TextView notificationView = (TextView) row.findViewById(R.id.tvNotif);
//here i wanted to get the data noOfMsgs
Toast.makeText(mContext, "noOfMsgs:" + numOfMsgs, Toast.LENGTH_LONG).show();
notificationView.setText(noOfMsgs);
return row;
}
}
您只需要初始化适配器并将适配器附加到ListView
ArrayList<String> items = new ArrayList<>();
items.add(item1);
items.add(item2);
items.add(item3);
CustomArrayAdapter<String> itemsAdapter = new CustomArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
listview.setAdapter(itemsAdapter);
您只需要更新在CustomArrayAdapter中传递的列表对象,然后通知该列表。
adapter.notifyDataSetChanged()
当您将列表对象传递给适配器时,列表中的所有更改都将在对象“数据”中自动更新。 您只需要更新视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.