0
我試圖在listSelector中使用,但state_selected和state_checked未按我的想法工作。我也嘗試在列表項XML中使用android:background標記中的選擇器,但它不起作用。由於當在多選模式中選擇時更改列表視圖項目的佈局背景顏色
我試圖在listSelector中使用,但state_selected和state_checked未按我的想法工作。我也嘗試在列表項XML中使用android:background標記中的選擇器,但它不起作用。由於當在多選模式中選擇時更改列表視圖項目的佈局背景顏色
試試這個辦法在你的活動
@Override
public void onItemClick(AdapterView<?> parent, View clickedView,
int position, long id) {
// TODO Auto-generated method stub
switch (clickedView.getId()) {
case R.id.itemLayoutId:
lytBackground = (LinearLayout) clickedView.findViewById(R.id.itemLayoutId);
lytBackground.setBackgroundColor(Color.parseColor("#0e95cf"));
break;
這裏lytBackground是你的ListView行項目的父佈局。
有像首先點擊排功能選擇和第二次點擊(在同一行),它被勾選,保存clickedView在一個全局變量
private View clickedView;
@Override
public void onItemClick(AdapterView<?> parent, View clickedView,
int position, long id) {
// TODO Auto-generated method stub
switch (clickedView.getId()) {
case R.id.itemLayoutId:
if (this.clickedView == clickedView) {
lytBackground = (LinearLayout) this.clickedView
.findViewById(R.id.itemLayoutId);
lytBackground .setBackgroundColor(Color.parseColor("#3eb4d8")); //normal color
}
lytBackground = (LinearLayout) clickedView.findViewById(R.id.itemLayoutId);
lytBackground.setBackgroundColor(Color.parseColor("#0e95cf")); // selected color
this.clickedView = clickedView;
break;
謝謝! :)我認爲這是可能的XML,但這不是一個壞的解決方案;) –