我正在创建聊天应用程序。所以我想添加用户从他的朋友那里得到的消息数量。为了表明我创建了自定义,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; }}
2 回答
烙印99
TA贡献1829条经验 获得超13个赞
您只需要更新您在 CustomArrayAdapter 中传递的列表对象,然后通知列表。
适配器.notifyDataSetChanged()
当您将列表对象传递给适配器时,列表中的任何更改都将在对象“数据”中自动更新。你只需要更新视图。
添加回答
举报
0/150
提交
取消