从 Activity 获取价值到自定义数组适配器

我正在创建聊天应用程序。所以我想添加用户从他的朋友那里得到的消息数量。为了表明我创建了自定义,Array adapter因为我的列表视图包含朋友姓名和notification textview.

http://img1.mukewang.com/613db4200001666806121016.jpg

所以,我的 list_of_registerd_users 活动中有数据:


http://img2.mukewang.com/613db42e0001ca9907920464.jpg

如何将此数据发送到自定义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;

    }

}



跃然一笑
浏览 175回答 2
2回答

烙印99

您只需要更新您在 CustomArrayAdapter 中传递的列表对象,然后通知列表。适配器.notifyDataSetChanged()当您将列表对象传递给适配器时,列表中的任何更改都将在对象“数据”中自动更新。你只需要更新视图。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java