android.widget.ArrayAdapter< T>只是接受的行模板, [英] android.widget.ArrayAdapter<T> just accept row template

查看:117
本文介绍了android.widget.ArrayAdapter< T>只是接受的行模板,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发包含ListAtivity类Android应用程序,并把它的数据如下:

I am developing an android application which contains a ListAtivity class and get it is data as follow :

ArrayAdapter<Item> ara=new MyArrayAdapter(this,_items);

setListAdapter(ara);

和我定义MyArrayAdapter:

And I defined MyArrayAdapter :

....
public MyArrayAdapter(Activity context, List<BirthdayContact> list) {
        super(context,R.layout.list_row,0,list);
        //super(context, R.layout.birthday_list, list);
        this.context = context;
        this.list = list;

    }
public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;

        if (convertView == null) {
            LayoutInflater inflator = context.getLayoutInflater();
            view = inflator.inflate(R.layout.birthday_list_row, null);
            final ViewHolder viewHolder = new ViewHolder();
            viewHolder._cName= (TextView) view.findViewById(R.id.contact_name);
            viewHolder._cImage = (ImageView) view.findViewById(R.id.contact_image);
            viewHolder._cbirthDay=(TextView)view.findViewById(R.id.contact_birthday_remained);

            view.setTag(viewHolder);
              }

......

......

但是,随着这种方式的问题在于,你不能只分配给每个row`s模板,你不能对列表视图,不是数据的列表的一部分其他部件。我的意思是我想有一个说一个TextView这表明消息的​​用户,下面我显示的行列表。

But the problem with this way is that you cant only assign each row`s template and you cant have other widget on list view which are not part of list of data. I mean I want to have a say a TextView which shows messages to user, and below that I show the list of rows.

你能帮助我吗?

推荐答案

如果你想有一个不同的布局不是一个简单的的ListView 你的内容视图设置的选项布局文件是这样的:

If you want a different layout than a simple ListView you have the option of setting the content view to a layout file like this:

setContentView(R.layout.layout_with_diferrent_views); // call this on the onCreate() method

其中, R.layout.layout_with_different_views 可能是一个XML的布局是这样的:

where R.layout.layout_with_different_views could be a xml layout like this:

<?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" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

由于您扩展 ListActivity 您必须在布局与ID 的ListView 元素> @android:ID /列表。当然,你可以有比上面,只要你有id为 @android一个的ListView 元素中的一个更复杂的布局:ID /列表

Because you extends ListActivity you must have in the layout a ListView element with the id @android:id/list. Of course you can have a more complex layout than the one above as long as you have a ListView element with the id @android:id/list

这篇关于android.widget.ArrayAdapter&LT; T&GT;只是接受的行模板,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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