How can I instantiate objects of type ArrayAdapter in Android
private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord>
LeScanRecord is a class too.
How can I instantiate objects of type ArrayAdapter in Android
private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord>
LeScanRecord is a class too.
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);
}
}
You can create objects of ArrayAdapter and use it as the ListView adapter :
ArrayAdapter<LeScanRecord> adapter = new ArrayAdapter<LeScanRecord>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
in which, values is a list of LeScanRecord objects to display in the listview.
For more information on using ArrayAdapter, you can study Simple ListView tutorial by AndroidExample.com.
You can also create custom Adapter for list components (ListView, GridView,Spinner , ....) by extending BaseAdapter, which is easier and more straightforward.
I recommend you to study another great article by Ravi Tamada, on Android ListViews, published on AndroidHive.info.