2011-10-11 25 views
2

我想爲我的定製ArrayAdapter傳遞多個數組。這是我的陣列和我想要做什麼:Android:定製ArrayAdapter中的多個陣列

String[] names = new String[]{ "One", "two", "three" }; 

String[] texts = new String[]{ "Bacon", "Eggs", "Cheese" }; 

Customadapter ap = new Customadapter(this, names, texts); 
setListAdapter(ap); 

,這裏是我的自定義ArrayAdapter:

public class Customadapter extends ArrayAdapter<String> { 

    private final Activity context; 
    private final String[] names; 

    public Customadapter(Activity context, String[] names) { 
     super(context, R.layout.row, names); 
     this.context = context; 
     this.names = names; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent){ 
     LayoutInflater inflater = context.getLayoutInflater(); 
     View rowView = inflater.inflate(R.layout.row, null, true); 
     TextView tw1 = (TextView) rowView.findViewById(R.id.label); 
     TextView tw2 = (TextView) rowView.findViewById(R.id.label2); 

     String text = names[position]; 
     tw2.setText(text); 

     return rowView; 

    } 

} 

回答

0

擴展BaseAdapter而不是ArrayAdapter的初學者,然後調整構造函數,以便它接受文本字符串,以便您可以將它存儲在適配器中。這應該主要是做這個伎倆。有一些方法需要重寫afaik,但它在文檔中存在。

1

而不必需要創建的ArrayAdapter<HashMap<String,String>>

+0

一個適配器也幫助我很多非常感謝ArrayAdapter<Strings>的! – user754730