5

У меня есть 2 ListView на одном фрагменте, и мне интересно, могу ли я установить для того же класса, который реализует AdapterView.OnItemClickListener.AdapterView.OnItemClickListener с большим количеством ListView

Я имею в виду, Android Документация говорит:

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

Added in API level 1 
Callback method to be invoked when an item in this AdapterView has been clicked. 

Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item. 

Parameters 
parent The AdapterView where the click happened. 
view The view within the AdapterView that was clicked (this will be a view provided by the adapter) 
position The position of the view in the adapter. 
id The row id of the item that was clicked. 

Так что я полагаю, что я могу выбрать другой ListView, который вызывается OnClick Материнского (AdapterView где произошел щелчок) ..

Теперь, как я могу определить ListView ? есть ли способ swicth/case? или мне нужно создать другой класс (также может быть анонимным, которого я знаю), который реализует onItemClickListener и устанавливает различия в ListView differents AdapterView.onItemClickListener?

ответ

13

Ok я решил:

private class myClass implements AdapterView.OnItemClickListener { 

    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 
     // TODO Auto-generated method stub 

     switch(parent.getId()) { 
     case R.id.listview1:    
      break; 
     case R.id.listview2: 
      break; 
     } 
    } 
} 
+0

Быки глаз! Большое спасибо за ответ. Решаемые. –

Смежные вопросы