我正在創(chuàng)建聊天應(yīng)用程序。所以我想添加用戶從他的朋友那里得到的消息數(shù)量。為了表明我創(chuàng)建了自定義,Array adapter因?yàn)槲业牧斜硪晥D包含朋友姓名和notification textview.所以,我的 list_of_registerd_users 活動(dòng)中有數(shù)據(jù):如何將此數(shù)據(jù)發(fā)送到自定義array adapter類以設(shè)置通知視圖:自定義數(shù)組適配器類: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貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
您只需要更新您在 CustomArrayAdapter 中傳遞的列表對(duì)象,然后通知列表。
適配器.notifyDataSetChanged()
當(dāng)您將列表對(duì)象傳遞給適配器時(shí),列表中的任何更改都將在對(duì)象“數(shù)據(jù)”中自動(dòng)更新。你只需要更新視圖。
添加回答
舉報(bào)
0/150
提交
取消