data0中的每一个字符串,都显示在R.layout.switcher_view里面(这里R.layout.switcher_view只是个模板,每一页的view是不同的)。如果你的data0不是String类型,应该会崩溃,不信你可以试试(我看过另一种list的源码,是将模板类强转为String的),除非你重写某些接口,自己产生view

解决方案 »

  1.   

    不,我当然是把ArrayAdatper也改成<ListView>的。实际上我就是想把几个ListView对象装进 ArrayAdapter里面;当然这样的话,那个R.Layout的xml文件写什么我就不知道了~,String可以用textView显示,但ListView~~.超级新手,不知道这种想法是不是有点白痴~,就充当ArrayAdapter的学习吧~
      

  2.   


        private View createViewFromResource(int position, View convertView, ViewGroup parent,
                int resource) {
            View view;
            TextView text;        if (convertView == null) {
                view = mInflater.inflate(resource, parent, false);
            } else {
                view = convertView;
            }        try {
                if (mFieldId == 0) {
                    //  If no custom field is assigned, assume the whole resource is a TextView
                    text = (TextView) view;
                } else {
                    //  Otherwise, find the TextView field within the layout
                    text = (TextView) view.findViewById(mFieldId);
                }
            } catch (ClassCastException e) {
                Log.e("ArrayAdapter", "You must supply a resource ID for a TextView");
                throw new IllegalStateException(
                        "ArrayAdapter requires the resource ID to be a TextView", e);
            }        T item = getItem(position);
            if (item instanceof CharSequence) {
                text.setText((CharSequence)item);
            } else {
                text.setText(item.toString());
            }        return view;
        }
    这是源代码,上面我说可能会崩溃,其实不会(对于ArrayAdapter来说),其中resource就是你传入的layout,由于有了这些代码:
    if (item instanceof CharSequence) {
                text.setText((CharSequence)item);
            } else {
                text.setText(item.toString());
            }
    就不会崩溃了,如果你的模板参数T是instanceof CharSequence,则直接强转(这没问题),如果不是,则调用Object的toString(这可能不是你想要的,比如说你的T是ListView的话,其toStirng其实是类名)
      

  3.   


    你不把ArrayAdatper也改成<ListView>,编译都有问题,我说的是运行崩溃。我看过ExpandableListAdapter的源代码,它也带模板参数T,而实际上这个T只能是String类型,因为它是强转String类型的。
    这我还发贴问过:
    http://topic.csdn.net/u/20110302/18/1528855d-7447-4378-bf90-0d2542f446f3.html