我如何可以实例ArrayAdapter
类型的对象类的Android安卓:实例化扩展ArrayAdapter
private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord>
LeScanRecord是一类了。
我如何可以实例ArrayAdapter
类型的对象类的Android安卓:实例化扩展ArrayAdapter
private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord>
LeScanRecord是一类了。
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);
}
}
谢谢。请给我一个答案。如果你觉得它有帮助 –
您可以创建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.
检查一些自定义列表视图的例子来学习另一个伟大的文章。你所需要做的就是定义正确的构造函数,并用它创建新的对象。 –