0

我如何可以實例ArrayAdapter類型的對象類的Android安卓:實例化擴展ArrayAdapter

private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord> 

LeScanRecord是一類了。

+0

檢查一些自定義列表視圖的例子來學習另一個偉大的文章。你所需要做的就是定義正確的構造函數,並用它創建新的對象。 –

回答

1
public class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord> { 

    Context context; 

    public LeDeviceListAdapter(Context context, int itemResource, List<LeScanRecord> itemList) { 
     super(context, itemResource, itemList); 
     this.context = context; 
     this.itemResource = itemResource; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder; 
     if (null == convertView) { 
      convertView = newView(parent); 
      // your functionality here 
     } 
     return 
    } 

private View newView(ViewGroup parent) { 
     return LayoutInflater.from(context).inflate(itemResource, parent, false); 
    } 
} 
+0

謝謝。請給我一個答案。如果你覺得它有幫助 –

1

您可以創建ArrayAdapter的對象,並把它作爲ListView控件適配器:其中

ArrayAdapter<LeScanRecord> adapter = new ArrayAdapter<LeScanRecord>(this, 
      android.R.layout.simple_list_item_1, android.R.id.text1, values); 

values在列表視圖中顯示LeScanRecord對象的列表。

有關使用ArrayAdapter的更多信息,你可以學習Simple ListView tutorial by AndroidExample.com.

您還可以通過擴展BaseAdapter創建列表組件定製適配器(ListView中,GridView控件,微調,....),這是更方便,更簡單。

我建議你通過Ravi Tamada, on Android ListViews, published on AndroidHive.info.