0

我有一个扩展 arrayAdapter 的类。我正在尝试将变量添加到列表中,但我不确定该怎么做。这是我当前的 ArrayAdapter 类。

class Item {
                String username;
                String number;
                String content;

            }         
             class ListAdapter extends ArrayAdapter<Item> {    
                public ListAdapter(Context context, int textViewResourceId) {
                    super(context, textViewResourceId);
                    // TODO Auto-generated constructor stub
                }    
                private List<Item> items;    
                public ListAdapter(Context context, int resource, List<Item> items)      
                   {    
                    super(context, resource, items);    
                    this.items = items;    
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {

                    View v = convertView;

                    if (v == null) {

                        LayoutInflater vi;
                        vi = LayoutInflater.from(getContext());
                        v = vi.inflate(R.layout.list_item, null);

                    }

                    final Item p = items.get(position);

                    if (p != null) {


                        TextView commentView = (TextView)v.findViewById(R.id.listComment);
                        TextView NumbersView = (TextView)v.findViewById(R.id.listNumber);
                        TextView usernamesView = (TextView)v.findViewById(R.id.listPostedBy);


                        commentView.setText(p.content);
                        NumbersView.setText(p.number);
                        usernamesView.setText(p.username);





                    }

                    return v;

                }
             }



                ListView yourListView = (ListView) findViewById(android.R.id.list);


                ListAdapter customAdapter = new ListAdapter(DashboardActivity.this, R.layout.list_item, tempList);

                yourListView .setAdapter(customAdapter);

这是我将数据添加到 ArrayList 的地方,

final List <Item> tempList = new ArrayList <Item>();


        String username = json2.getString(KEY_USERNAME);
        String number = json2.getString(KEY_NUMBER);
        String content = json2.getString(KEY_COMMENT);

       //The Error occurs here
        tempList.add ( new Item (username, number,content));

错误说The constructor ClipData.Item(String, String, String) is undefined

4

1 回答 1

6

那是因为您没有与该签名匹配的构造函数。简单地做一个。

class Item {

     String username;
     String number;
     String content;

     public Item (String username, String number, String content){
     this.username = username;
     this.number = number;
     this.content = content;
     }

}
于 2013-08-22T18:55:39.063 回答