0

How can I instantiate objects of type ArrayAdapter in Android

private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord> 

LeScanRecord is a class too.

1
  • check some custom listview examples. All you need to do is define right constructor and just create new object with that. Commented Mar 6, 2016 at 8:18

2 Answers 2

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);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Please me it an answer. If you find it helpful
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.