1. android listView 怎麼指定項的背景設置
android listview指定項設定背景步驟如下:
監聽列表項監聽事件,取得被點擊的view,設置為:view.setSelector("true");
2.在適配器塌鎮中,用if-else語句,判斷選擇的列表項設置背景,沒有選中的則默認背景,代碼如下:
java">try{
if(selectItem==position){
messagetitle.setTextColor(android.graphics.Color.BLACK);
messagetime.setTextColor(android.graphics.Color.BLACK);
viewHolder.messagetitle.setText(maps.get(position)
.get("messagetitle").toString());
viewHolder.messagetime.setText(maps.get(position)
.get("messagetime").toString());
convertView.findViewById(R.id.expandable1)
.setBackgroundColor(android.graphics.Color.WHITE);
convertView.findViewById(R.id.expandable1)
.setBackgroundResource(R.drawable.menu_shapeclick);
}else{
messagetitle.setTextColor(android.graphics.Color.WHITE);
messagetime.setTextColor(android.graphics.Color.WHITE);
viewHolder.messagetitle.setText(maps.get(position)
.get("messagetitle").toString());
viewHolder.messagetime.setText(maps.get(position)
孫鬧.get("messagetime").toString());
convertView.findViewById(R.id.expandable1)
.setBackgroundResource(
團凱粗R.drawable.menu_shapeunonclick);
}
}catch(Exceptionex){
ex.printStackTrace();
}
returnconvertView;