0

在我的應用程序,我使用此代碼顯示列表視圖與科。 但這種方式我不能得到那個該列表項,我要選擇。我的意思是,當我要按任何列表項目時,我無法看到變色。因此,如何有可能使該代碼:爲什麼我無法顯示列表視圖被點擊?如何讓它成爲可能?

public static ProgressDialog m_progressDialog; 
    public Map<String,?> createItem(String title, String caption) { 
     Map<String,String> item = new HashMap<String,String>(); 
     item.put(ITEM_TITLE, title); 
     item.put(ITEM_CAPTION, caption); 
     return item; 
    } 

    @Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.main); 

     // create our list and custom adapter 
     SeparatedListAdapter adapter = new SeparatedListAdapter(this); 
     adapter.addSection("Local documents:", new ArrayAdapter<String>(this, 
      R.layout.list_item, new String[] { "WindowsONE Mobile PK", "WindowsorONE Moldings","Filet for a burger video" })); 
     adapter.addSection("Non-local resources:", new ArrayAdapter<String>(this, 
       R.layout.list_item, new String[] { "Launch Photo slideshow link", "Dealer locator link" })); 
     adapter.addSection("Send emails:", new ArrayAdapter<String>(this, 
       R.layout.list_item, new String[] { "Send Dealer Locator email", "Send Catalog email","Send install instrucation link" })); 
     //For extra Information in Listview  
     //adapter.addSection("Non-local resources:", new SimpleAdapter(this, security, R.layout.list_complex, 
     //new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));   
     ListView list = getListView(); 
     list.setAdapter(adapter); 
     list.setTextFilterEnabled(true); 
     list.setOnItemClickListener(this); 
} 

}

+0

我想我必須使用Customadapter或圖像適配器。但我很困惑,如何實現這個靜態值。那麼請讓anybudy幫我實現這個代碼? –

回答

1

可以定義一個觸摸監聽到你的列表視圖,可以顯示觸摸像

ListView.setOnTouchListener(List_onTouch); 

添加一個名爲List_onTouch的觸摸列表器

OnTouchListener List_onTouch=new OnTouchListener(){ 
@Override 
public boolean onTouch(View arg0,MotionEvent arg1){ 
    int iAction=arg1.getAction(); 
    if(iAction==0){ 
     ls2.setBackgroundcolor(Color.white); 
    } 
    else{ 
ls2.setBackgroundcolor(Color.orange);  
    } 
    return false; 
} 
}; 

LS2是你listViewObject,如果你點擊列表將您的顏色變爲橙色

+0

然後如何獲得ListView的選定索引? –

+0

我使用這個,但與我的代碼,它不會工作。 –

+0

@iDroidExplorer可以發佈您的代碼嗎? –

1

試試這個

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
相關問題