自定义ListView项目ID

时间:2015-03-31 21:46:12

标签: android android-listview

我正在尝试设置我的应用程序的某些选项的活动,我想使用具有3种不同类型视图的自定义列表视图,这是我的自定义列表视图的代码:

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;
    }
}

我在活动中使用CustomListAdapter:

mList = (ListView)findViewById(R.Id.listView1);
CustomListAdapter adapter = new CustomListAdapter(this, texts);
mList.setAdapter(adapter);

现在我想获得不同布局的输入窗口小部件的ID,有没有办法做到这一点?

谢谢

0 个答案:

没有答案
相关问题