2014-06-09 86 views

回答

0

試試這個辦法在你的活動

@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; 
+0

謝謝! :)我認爲這是可能的XML,但這不是一個壞的解決方案;) –

相關問題