Skip to content Skip to sidebar Skip to footer

How To Use Getview() With A Simpleadapter In Android?

I am generating a ListView using a SimpleAdapter. My SimpleAdapter code is as follows: ListAdapter k = new SimpleAdapter(this, val1, R.layout.mytask, new String[]{'TaskId', 'headin

Solution 1:

You can do it this way:

ListAdapterk=newSimpleAdapter(...) {
    @Overridepublic View getView(int position, View convertView, ViewGroup parent) {
        Viewview=super.getView(position, convertView, parent);
        ...
        return view;
    }
}

Solution 2:

Try this,

publicclassAdapterextendsSimpleAdapter{
        HashMap<String, String> map = new HashMap<String, String>();
        public Adapter(Context context, List<?extends Map<String, String>> data,
                int resource, String[] from, int[] to) {
            super(context, data, resource, from, to);
        }
    @Override
        public View getView(int position, View convertView, ViewGroup parent){


          // You can customize here.

        }

    }

Instead of calling new SimpleAdapter you can call something like this

 Adapter mAdapter = new Adapter(params);

Keep this class as a subclass in your activity itself,

Solution 3:

Create class which extends SimpleAdapter and override it's methods. don't forget to handle the constructor and call super(...)

Post a Comment for "How To Use Getview() With A Simpleadapter In Android?"