2012-10-03 68 views
1

我是新開發的android,我試圖做一個ListActivity與標題和副標題。 到目前爲止,只有設法使標題:android ListActivity with subtitle

this.data = new ArrayList<String>(); 

// add some objects into the array list 
this.data.add("YOU WILL HEAR"); 
this.data.add("USEFUL PHRASES"); 
this.data.add("VOCABULARY"); 
this.data.add("DIALOGUES"); 
this.data.add("INFORMATION"); 

this.port = new ArrayList<String>(); 
this.port.add("BEM VINDO"); 
this.port.add("FRASES ÚTEIS"); 
this.port.add("VOCABULÁRIO"); 
this.port.add("DIÁLOGOS"); 
this.port.add("VOCABULÁRIO"); 

this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,R.id.title,this.data)); 

ListView lv = getListView(); 

這個代碼是在onCreate方法。

我的問題是,我如何可以用第二個數組填充R.id.subtitle

回答

0

試試下面的代碼:

 public ListView lv; 

      lv = (ListView) findViewById(R.id.ListView01); 
      lv.setAdapter(adapter); 
    lv.setTextFilterEnabled(true); 
    lv.setBackgroundResource(R.drawable.background); 
    lv.setCacheColorHint(00000000); 
    lv.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 


     } 
    }); 


     class MySimpleArrayAdapter extends ArrayAdapter<String> { 
    private Context context; 

    public MySimpleArrayAdapter(Context context) { 
     super(context, R.layout.list); 
     this.context = context; 

    } 

    public int getCount() { 
     return names.size(); 
    } 

    public long getItemId(int position) { 
     return position; 
    } 


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

     View rowView = convertView; 

     if (rowView == null) { 

      LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      rowView = vi.inflate(R.layout.list, null); 
     } 
     TextView name = (TextView) rowView.findViewById(R.id.Name); 
     TextView number = (TextView) rowView.findViewById(R.id.no); 


     return rowView; 
    } 
}