2014-10-16 30 views

回答

0

你應該在你的getView()方法中做到這一點。每次點擊某個項目時,都應該再次設置適配器並重新加載列表。這是我可以告訴你沒有看到你的代碼。

+0

我只需要使用XML選擇你的位置。 – 2014-10-16 14:43:07

0

你可以試試我的想法: 創建整型變量,將節省在onItemClick

public class Activity implements onItemClickListener{ 
private int prevPosition; 
..... 

list.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, 
       long id) { 

      prevPosition = position; 
      //call your adapter here then use notifyDataSetChanged(); 
     } 
    }); 
CustomAdapter{ 
...... 
getView(int position, View convertView, ViewGroup parent){ 

//setCondition 
if(prevPosition == position){ 
//do something here for your selected item list 
textView.setBackground(getResources().getDrawable(R.drawable.selectedBackground)); 
} 
else{ 
///do something here for unselected list item 
layout.setBackground(getResources().getDrawable(R.drawable.unselectedBackground)); 
} 
相關問題