ArrayAdapter的getView()方法是没有得到所谓的 [英] The getView() method of ArrayAdapter is not getting called

查看:404
本文介绍了ArrayAdapter的getView()方法是没有得到所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的Andr​​oid开发。我试图构建与(这是通过添加片段)标记的应用程序。在片段中的一个,我想显示一个列表。这份名单已经用ListAdapter我从ArrayAdapter延长填充,我已经超载get​​View()方法。
这是我的片段

I am very new to android development. I am trying to a build an application with tags (which are added through fragments). In one of the fragments, I am trying to display a list. This list has been populated using ListAdapter which I have extended from ArrayAdapter and I have overloaded getView() method. This is my fragment

public class tabcontentActivity extends Fragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        if (container == null) {
            return null;
        }
        View v = (LinearLayout) inflater.inflate(R.layout.tablayout, container,
            false);
        ListView lv = (ListView) v.findViewById(R.id.listview1);
        ListViewAdapter adapter = new ListViewAdapter(container.getContext(),
            android.R.layout.simple_list_item_1, R.id.textview1);
        adapter.notifyDataSetChanged();
        lv.setAdapter(adapter);

        return v;
    }
}

这是多么我已经实现了ListAdapter

And this is how I have implemented the ListAdapter

public class ListViewAdapter extends ArrayAdapter {
    Context context1;

    public ListViewAdapter(Context context,int resource, int textViewResourceId) {
        super(context,resource,textViewResourceId);
        this.context1 = context;
        System.out.println("here aswell!!!!!!");
        // TODO Auto-generated constructor stub
    }

    public View getView(int arg0, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub
        System.out.println("@@@I AM HERE@@@");
        LayoutInflater inflater = LayoutInflater.from(context1);
        convertView = inflater.inflate(R.layout.tablayout, null);

        TextView wv = (TextView) convertView.findViewById(R.id.textview1);
        String summary = "<html><body><h1>This is happening!!!</h1></body></html>";
        wv.setText(Html.fromHtml(summary));

        convertView.setTag(wv);

        return convertView;
    }
}

布局XML是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listview1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </ListView>

    <TextView
        android:id="@+id/textview1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="myreader" />

</LinearLayout>

请帮我找到了一种方法,我可以使这项工作。

Please help me to find a way by which I can make this work.

推荐答案

您刚才忘了提供数据的构造函数,然后让在构造函数中调用正确:

You just forgot to provide the data to the constructor and then make the correct call within the constructor:

public ListViewAdapter(Context context,int resource, int textViewResourceId, List<YourObjectType> items) {
    super(context,resource,textViewResourceId, items);
    this.context1 = context;
    // TODO Auto-generated constructor stub
}

这篇关于ArrayAdapter的getView()方法是没有得到所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆