Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我有一个关于android listView和baseAdapter的奇怪情况?_Android_List_Listview_Baseadapter - Fatal编程技术网

我有一个关于android listView和baseAdapter的奇怪情况?

我有一个关于android listView和baseAdapter的奇怪情况?,android,list,listview,baseadapter,Android,List,Listview,Baseadapter,这是我的密码: public class MyAdapter extends BaseAdapter{ private LayoutInflater mInflater; ViewHolder holder = null; public MyAdapter(Context context){ this.mInflater = LayoutInflater.from(context); } @Override public int

这是我的密码:

public class MyAdapter extends BaseAdapter{
    private LayoutInflater mInflater;
    ViewHolder holder = null;

    public MyAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mData.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        /**Original holder
         * 
         * 
         * */
        //ViewHolder holder = null;
        if (convertView == null) {

            holder=new ViewHolder();  
            convertView = mInflater.inflate(R.layout.country_list_row, null);
            holder.countryName=(TextView)convertView.findViewById(R.id.country_text);
            holder.check = (CheckBox)convertView.findViewById(R.id.country_check);
            convertView.setTag(holder);

        }else {                 
            holder = (ViewHolder)convertView.getTag();

        }
        holder.check.setTag(new Integer(position));

        Log.v("In CountryList","mData.get("+position+").get(country) = "+(String)mData.get(position).get("country"));       

        holder.countryName.setText((String)mData.get(position).get("country"));
        if (position == countryIndex){
            Log.v("In CountryList onCreate","before setChecked(true), countryIndex=="+countryIndex);       
            Log.v("In CountryList onCreate","before setChecked(true), position=="+position);       
            holder.check.setChecked(true);
        }else{
            Log.v("In CountryList onCreate","setChecked(false), countryIndex=="+countryIndex);       
            Log.v("In CountryList onCreate","setChecked(false), position=="+position);       
            holder.check.setChecked(false);
        }

        holder.check.setOnCheckedChangeListener(new myCheckBoxListener(position));

        return convertView;
    }



}
我发现这个位置一直在0-8之间循环。但是,我也可以使用“(String)mData.get(position).get(“country”)不重复地从mData获取正确的对象。谁能告诉我为什么。

看看这个:

顺便说一句,您的listview一次显示大约7-9行吗?

看看这个:

顺便问一下,您的listview一次显示大约7-9行吗