Better way to implement custom views in a listview with simpleadapter?

Posted by jonaz on Stack Overflow See other posts from Stack Overflow or by jonaz
Published on 2013-06-25T18:56:05Z Indexed on 2013/06/25 22:21 UTC
Read the original article Hit count: 160

I have a value called tags which is a comma separated list of words. I want to put this into nicely designed "tag-buttons".

The below works. However the line ((LinearLayout) view).removeAllViews(); seems like an ugly fix for not adding the tags multiple times every time adapter.notifyDataSetChanged(); is called after i load more rows with a setOnScrollListener()

Any suggestion to "best practice" here, or at least a more good looking solution?

adapter = new SimpleAdapter(activity,data,
    R.layout.list_transactions,
    new String[] {"comment", "amount","date","tags","category"},
    new int[] { R.id.comment, R.id.amount,R.id.date,R.id.tags_container,R.id.category }
  );


SimpleAdapter.ViewBinder binder = new SimpleAdapter.ViewBinder() {
    @Override
    public boolean setViewValue(View view, Object object, String value) {
    //Log.d(TAG,"view.toString()= "+ view.toString());
    if (view.getId() == R.id.tags_container)
    {

        String[] tags = value.split(",");

        ((LinearLayout) view).removeAllViews();
        for (String tag : tags) {
        View v = createTagView(activity.getLayoutInflater(),tag);
        ((LinearLayout) view).addView(v);

        }
        return true;
    }
    return false;
    }
};

© Stack Overflow or respective owner

Related posts about java

Related posts about android