2011-08-19 5 views
1

헤더가있는 목록보기가 있습니다. 목록 헤더에 '이동'버튼이 있습니다. 그리고 그 클릭에 대한 사용자 지정 어댑터에서 사용자 지정 메서드를 호출해야합니다. 어댑터 onlick 리스터에서 어댑터 참조를 어떻게 얻을 수 있습니까?listview 헤더 버튼에 대한 onlick listner 내에서 어댑터 참조 얻기

public class GroupListActivity extends ListActivity { 
... 
private void createGroupList() { 

    final ListView listView = getListView(); 

    final View view = getLayoutInflater().inflate(R.layout.multi_list_groups_header, listView, false); 
    listView.addHeaderView(view, null, true); 
    TextView listHeader = (TextView) findViewById(R.id.groupsHeader); 
    Button goButton = (Button) findViewById(R.id.goButton); 

    this.gAdapter = new GroupAdapter(this, R.layout.multi_list_groups2, gStore, true); 
    this.setListAdapter(this.gAdapter); 
    //listView.setFocusable(false); 
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 

    goButton = (Button) findViewById(R.id.goButton); 
    goButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Log.e(MY_DEBUG_TAG,"Manual Go!!"); 
      // I need to call the adapters' getCheckedItems() method here 
     } 
    }); 
} 

사용자 정의 어댑터

public class GroupAdapter extends ArrayAdapter<Group> { 
    ... 
    public HashMap<String, String> getCheckedItems() { 
     return checkedItems; 
    } 
} 

답변

1

아마도 당신은 당신의 GroupAdapter의 기준에 보유하고 사용자 정의 Button을 만들려고합니다. 이렇게하면 개체를 사용자 지정 Button으로 전송 한 다음 GroupAdapter을 가져올 수 있습니다.

@Override 
    public void onClick(View v) { 
     Log.e(MY_DEBUG_TAG,"Manual Go!!"); 
     Map<String, String> checkedItems = ((MyButton)v).getGroupAdapter().getCheckedItems(); 
    } 
+0

어떻게 사용자 정의 버튼에 어댑터 참조가 있습니까? –

+0

어댑터에서 가져올 생성자를 정의하면 해당 참조를 보유 할 수 있습니다. –

관련 문제