如何在Android中使用带有SimpleAdapter的getview()?

时间:2014-04-07 05:50:11

标签: android listview view simpleadapter

我使用ListView生成SimpleAdapter。我的SimpleAdapter代码如下:

ListAdapter k = new SimpleAdapter(this, val1, R.layout.mytask, new String[]{"TaskId", "heading", "status"}, new int[]{R.id.View1, R.id.View2, R.id.ViewStatus}); 

我的活动是MainActivity extends Activity。 我想override getview()方法。我怎样才能做到这一点?

3 个答案:

答案 0 :(得分:6)

你可以这样做:

ListAdapter k = new SimpleAdapter(...) {
    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        ...
        return view;
    }
}

答案 1 :(得分:1)

试试这个,

  public class Adapter extends SimpleAdapter{
        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.

        }

    }

您可以拨打此类内容

,而不是拨打new SimpleAdapter
 Adapter mAdapter = new Adapter(params);

将此类保留为活动本身的子类,

答案 2 :(得分:0)

创建扩展Si​​mpleAdapter的类并覆盖它的方法。不要忘记处理构造函数并调用super(...)