特定の行のListViewの背景を設定する方法。Android setbackgroundまたはテキストの色muticolumn Listviewの特定の行
ListView list = getListView();
sd = new SimpleAdapter(this, routhPath, R.layout.route_path,new String[] {"routeCode","routeName","outlets" },new int[] { R.id.routeCode,R.id.routeName,R.id.outlets});
list.setAdapter(sd);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setSelected(true);
list.setTextFilterEnabled(true);
list.setItemsCanFocus(true);
list.setSelectionAfterHeaderView();
if(isVisitedToVisitHeader()){
if(defaultRoutePos != 0){
Log.i("-----" ,"---defaultRoutePos---" + defaultRoutePos +" --count-- "+list.getChildCount());
list.setItemChecked(defaultRoutePos, true);
// list.getChildAt(positions).setBackgroundColor(R.color.red);
//list.getChildAt(defaultRoutePos).setBackgroundColor(R.color.red);
}
}
これは私がonCreate()
で鼎午前0.Thisに一部を与えるSimpleAdapter
.Here list.getChildCount()
を使用して行っている.I私のコードです。
...事前
不可のこの回答。独自の 'getView()'のきめ細かな制御が必要です。 'ListView'はビューをリサイクルし、現在表示されているもの(6項目前後)の外の位置は物理的に存在しないことを覚えておく必要があります。 'listview.getChildAt()'はN番目の* visible *の行を返しますので、位置は正しくマップされません。 – dmon