天天看點

item 點選效果 點選變色,再點一下又變回原來的顔色,沒有點到的item顔色都是預設顔色...

mlvGuaranteedInfo = (ListView) mvContent.findViewById(R.id.lv_guaranteed_info);

mlvGuaranteedInfo.setOnItemClickListener(new GuaranteedInfoListener());                
/**
 * ListView點選效果
	 */
	private class GuaranteedInfoListener implements OnItemClickListener {
		@Override
		public void onItemClick(AdapterView<?> parent, View arg1, int position, long id) {
			ListView listView = (ListView) parent;
			int visiblePostion = listView.getFirstVisiblePosition();
			for (int i = 0; i < mlvGuaranteedInfo.getChildCount(); i++) {
				if (i == position - visiblePostion) {
					// mlvGuaranteedInfo.getChildAt(i).setBackgroundResource(R.color.color_image_data_line_choosen);
					if (mintGuaranteedInfoPosition == i) {
						mlvGuaranteedInfo.getChildAt(i).setBackgroundResource(R.drawable.selector_bg_listview_item);
						
					} else {
						mlvGuaranteedInfo.getChildAt(i).setBackgroundResource(R.color.color_image_data_line_choosen);
						
					}
				} else {
					mlvGuaranteedInfo.getChildAt(i).setBackgroundResource(R.drawable.selector_bg_listview_item);
				}
			}
			
		}
	}                

版權聲明:本文為CSDN部落客「weixin_34274029」的原創文章,遵循CC 4.0 BY-SA版權協定,轉載請附上原文出處連結及本聲明。

原文連結:https://blog.csdn.net/weixin_34274029/article/details/92318809

繼續閱讀