0
リストビューで特定の行の色を設定したい場合、その行は実行時に認識されます。 ...私はこれをどのように行うことができますを教えてくださいAndroid setcolour listview特定の行(特定の行のみ)
リストビューで特定の行の色を設定したい場合、その行は実行時に認識されます。 ...私はこれをどのように行うことができますを教えてくださいAndroid setcolour listview特定の行(特定の行のみ)
一つの方法は、あなたがしたい行のインデックスを使用することで、事前に
感謝を
ArrayList<SalesRoutes> routeList = getSalesRoute();
ArrayList<HashMap<String, String>> routhPath = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < routeList.size(); i++) {
if(Integer.parseInt(routeList.get(i).getOutlets()) >0){
HashMap<String, String> map = new HashMap<String, String>();
map.put("routeCode",((SalesRoutes) routeList.get(i)).getRouteCode());
map.put("routeName",((SalesRoutes) routeList.get(i)).getDescription());
map.put("outlets", ((SalesRoutes) routeList.get(i)).getOutlets());
routhPath.add(map);
}
}
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});
row = getLayoutInflater().inflate(R.layout.route_path_row, null, false);
getListView().addHeaderView(row);
list.setAdapter(sd);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setSelected(true);
//list.setSelection(0);
list.setTextFilterEnabled(true);
list.setItemsCanFocus(true);
list.setItemChecked(positions, true);
list.setSelectionAfterHeaderView();
:私はこのようなリストビューを行ってahve getuchView()。getChildAt(index).setBackground(#ff0000); のようになります。
それ以外の場合は、カスタム・アダプターを作成し、各行のレンダリング前に呼び出されるgetViewメソッドを上書きする必要があります。これを使って条件をチェックし、それに応じて背景を設定することができます。 http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
上記はチュートリアルです。