2011-07-25 112 views
1

嗨,大家好我一直在寻找方式来获取自定义列表视图的细节。例如,我有listview,其中包含复选框的自定义视图将被嵌入。我需要做的只是点击按钮来查找复选框的状态。还需要知道如何使用getAdapter方法在这种情况下..提前Android自定义列表视图获取适配器

谢谢..

编辑#1

class MyEthnicityAdapter extends BaseAdapter { 
    Context rContext; 
    private LayoutInflater rInflater; 
    View view; 
    public MyEthnicityAdapter(Context c) { 

     rInflater = LayoutInflater.from(c); 

     rContext = c; 

    } 

    @Override 
    public int getCount() { 
     /* return Library.s.size(); */ 
     return getResources().getStringArray(R.array.ethnicity).length; 
    } 

    @Override 
    public Object getItem(int position) { 

     // return null; 
     System.out.println("My view l;st size is===> " + viewList.size()); 
     //return viewList.get(position); 
     return view; 
    } 

    @Override 
    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    @Override 
    public View getView(final int position, View convertView, 
      ViewGroup parent) { 
     // TODO Auto-generated method stub 
     convertView = rInflater.inflate(R.layout.custom_multi_select, null); 
     EthinicityDataClass mydat = new EthinicityDataClass(); 

     mydat.ethinicitycheck = (CheckBox) convertView 
       .findViewById(R.id.ethnicity_check); 

     mydat.ethinicitycheck.setText(getResources().getStringArray(
       R.array.ethnicity)[position]); 


     view=convertView; 
     return convertView; 
    } 

    class EthinicityDataClass { 

     CheckBox ethinicitycheck; 
    } 

} 

,我设置适配器这样的。 ethnicityListview = (ListView) findViewById(R.id.ethnicityListview); ethnicityListview.setAdapter(new MyEthnicityAdapter(this));

回答

0

如果你这样做:

ethnicityListview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 

可以使用

ethnicityListview.isItemChecked(position); 

获得getView方法中的指定项目的检查状态并做出反应的价值存在(检查项目如果选中,取消选中则取消选中)。

相关问题