2013-08-22 3 views
0

나는 arrayAdapter 클래스를 가지고 있습니다. 목록에 변수를 추가하려고하지만 정확히 어떻게해야하는지 잘 모르겠습니다. 다음은 현재 사용중인 ArrayAdapter 클래스입니다. 내가 ArrayList에 데이터를 추가 곳에있다ArrayList에 데이터를 올바르게 추가하는 방법 - Android

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); 

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

답변

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; 
    } 

} 
관련 문제