Android 自定义ListView项目ID
我正在尝试创建一个活动,用于设置我的应用程序的某些选项,我想使用具有3种不同类型视图的自定义listview,这是我的自定义listview的代码:Android 自定义ListView项目ID,android,android-listview,Android,Android Listview,我正在尝试创建一个活动,用于设置我的应用程序的某些选项,我想使用具有3种不同类型视图的自定义listview,这是我的自定义listview的代码: public class CustomListAdapter extends ArrayAdapter<String>{ String[] text; Context context; CheckBox chkBox; public CustomListAdapter(Activity context,
public class CustomListAdapter extends ArrayAdapter<String>{
String[] text;
Context context;
CheckBox chkBox;
public CustomListAdapter(Activity context, String[] text){
super(context, R.layout.layout_checkbox, text);
this.text = text;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View single_row = null;
if(position<4){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
single_row = inflater.inflate(R.layout.layout_checkbox, null, true);
TextView tv = (TextView)single_row.findViewById(R.id.textView1);
tv.setText(text[position]);
chkBox = (CheckBox)single_row.findViewById(R.id.checkBox1);
}else{
if(position<6){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
single_row = inflater.inflate(R.layout.layout_phone, null, true);
TextView tv = (TextView)single_row.findViewById(R.id.textView1);
tv.setText(text[position]);
}
}
if(position==6){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
single_row = inflater.inflate(R.layout.layout_mail, null, true);
TextView tv = (TextView)single_row.findViewById(R.id.textView1);
tv.setText(text[position]);
}
return single_row;
}
}
现在我想获得不同布局的输入小部件的ID,有没有办法做到这一点
谢谢你你到底是什么意思??什么时候需要这些ID?当我需要访问输入小部件的值时,我需要活动中的ID,比如输入文本或复选框。一种方法是,可以对这些视图设置标记,然后使用findViewByTag查找它们
mList = (ListView)findViewById(R.Id.listView1);
CustomListAdapter adapter = new CustomListAdapter(this, texts);
mList.setAdapter(adapter);