5

하나의 조각에 2 개의 ListView가 있고 AdapterView.OnItemClickListener를 구현하는 동일한 클래스를 둘 다 설정할 수 있는지 궁금합니다. 내 말은ListView가 더 많은 AdapterView.OnItemClickListener

는 안드로이드 문서는 말한다 :

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. 

그래서 내가 부모에 의해 (클릭이 발생한 어댑터 뷰 AdapterView)를 온 클릭을 호출 다른 목록보기를 선택할 수 있다고 가정 ..

을 지금은 ListView를 식별 할 수있는 방법 ? 거기에 swicth/case 방법이 있습니까? 또는 onItemClickListener를 구현하고 differents로 설정된 다른 클래스를 만들 필요가 있습니다 (익명으로도 가능함). ListView differents AdapterView.onItemClickListener?

답변

13

좋아, 내가 해결 :

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

황소 눈! 답변을 주셔서 감사합니다. 해결 됐어. –

관련 문제