2015-01-11 11 views
1

나는이 방법으로 어댑터를 통해 몇 가지 목록 항목을 추가했습니다.해당 목록 항목과 관련된 데이터 가져 오기 setOnItemClickListener 통해

classStudentsCollection.add(new mClassStudents(R.drawable.ic_profile, "DataOne", "DataTwo", "DataThree")); 

그리고 이러한 목록 항목 중 하나를 클릭 이벤트로 수신하는 수신기가 있습니다.

classStudentsView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       Toast.makeText(mainAppContext, "position" + position + "id "+id, Toast.LENGTH_SHORT).show(); 
       //get data associated with this particular list object 
      } 
     }); 

지금 나는이 mClassStudents 목록 개체와 관련 된 모든 데이터를 검색 할 수 있습니다. 값 "DataOne", "DataTwo", "DataThree"을 검색합니다.

어떻게하면됩니까? 도와주세요.

답변

2

당신이 클릭 개체를 검색하려면, 당신은 단지

parent.getItemAtPosition(position); 

를 호출하고 특정 개체에 반환 값을 캐스팅 할 수 있습니다. 사용자 정의 어댑터를 만든 경우 제대로 작동하려면 getItem이 같은 항목을 반환해야합니다.

관련 문제