我有一个名为 tags 的值,它是一个逗号分隔的单词列表。我想把它放入设计精美的“标签按钮”中。
下面的作品。但是,在我加载更多行后((LinearLayout) view).removeAllViews();
,每次adapter.notifyDataSetChanged();
调用不多次添加标签时,这条线似乎是一个丑陋的修复setOnScrollListener()
对这里的“最佳实践”有什么建议,或者至少是一个更好看的解决方案?
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;
}
};