点击后,变色,先前点击的不能恢复以前的颜色。


问题是,点击后,变色,先前点击的不能恢复以前的颜色。


 第一个:设置listview的getview中的最外层界面的监听事件。

private class 最外层界面 implements OnClickListener {
private int position;
public SingleChoiceListener(int position) {
this.position = position;
}

public void onClick(View arg0) {
items.get(position).checked = true;
for (int i = 0; i < items.size(); i++) {
if (i != position) {
items.get(i).checked = false;
}
}
WallPaperAdapter.this.notifyDataSetChanged();
}
}
第2个方法:在setOnItemClickListener中

class BottomListener implements OnItemClickListener {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
adapter类.SetFocus(arg2);
}
}

public void SetFocus(int index) {
this.index = index;
// this.notifyDataSetChanged();
this.notifyDataSetInvalidated();//刷新界面
}
然后在getview中设置你的背景颜色呵呵。
public View getView(int position, View convertView, ViewGroup parent) {
myview = layoutinflater.inflate(R.layout.group_bottom_item, null);
ImageView imageview = (ImageView) myview.findViewById(R.id.imageview_bottom);
TextView textview = (TextView) myview.findViewById(R.id.textview_bottom);
if (position == 0) {
imageview.setBackgroundResource(android.R.drawable.ic_menu_mapmode);
textview.setText(R.string.Group_Item_Main);
}
if (position == 1) {
imageview
.setBackgroundResource(android.R.drawable.ic_menu_myplaces);
textview.setText(R.string.Group_Item_My);
}
if (position == 2) {
imageview.setBackgroundResource(android.R.drawable.ic_menu_share);
textview.setText(R.string.Group_Item_square);
}
if (position == 3) {
imageview.setBackgroundResource(android.R.drawable.ic_menu_more);
textview.setText(R.string.Group_Item_More);
}
if(position==index){
myview.setBackgroundResource(R.drawable.css_biaoqian);
}else{
myview.setBackgroundResource(0);
}
return myview;
}
}
希望对你有帮助。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值