ArrayAdapter< D​​ummyContent.DummyItem>与android.R.layout.simple_list_item_activated_2 [英] ArrayAdapter<DummyContent.DummyItem> with android.R.layout.simple_list_item_activated_2

查看:484
本文介绍了ArrayAdapter< D​​ummyContent.DummyItem>与android.R.layout.simple_list_item_activated_2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用在我的Andr​​oid应用程序项目的主/详细流程。现在,我想不仅创建项目的列表只有一个字符串。我想标准的DummyItem类更改为以下内容:

I'm currently using the master / detail flow in my android application project. Now I would like to not only create a list with items with only one string. I'd like to change the standard DummyItem class to the following:

     /**
     * A dummy item representing a piece of content.
     */
    public static class DummyItem {
        public String id;
        public String content;
        public String subtext; //Added subtext variable here
        public DummyItem(String id, String content, String subtext) {
            this.id = id;
            this.content = content;
            this.subtext = subtext; //And here
        }

        @Override
        public String toString() {
            return content;
        }
    }

在ItemListFragment类我在这行code $ P $为列表创建适配器对定义的:

In the ItemListFragment class I'm having this line of code pre-defined for creating the adapter for the list:

    setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(), 
                   android.R.layout.simple_list_item_activated_1, 
                   android.R.id.text1, 
                   DummyContent.ITEMS));

但我想更改 android.R.layout.simple_list_item_activated_1 android.R.layout.simple_list_item_activated_2

虽然具有 android.R.id.text1 的内容和 android.R.id.text2 我的潜台词 -variable。

while having android.R.id.text1 as content and android.R.id.text2 as my subtext-variable.

有没有可能做到这一点?

Is there a possibility to do this?

推荐答案

重写getView一个ArrayAdapter()方法。应该是这样的:

Overwrite the getView() Method of the ArrayAdapter. Should be something like this:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    //super call to create / recycle the view
    View view = super.getView(position, convertView, parent);

    TextView textView1 = (TextView) view.findViewById(android.R.id.text1);
    textView1.setText(getItem(position).getContent());

    TextView textView2 = (TextView) view.findViewById(android.R.id.text2);
    textView2.setText(getItem(position).getSubtext());

    return view;

}

下面是一些进一步的阅读列表视图,包括示例:
http://www.vogella.com/tutorials/AndroidListView/article.html

Here's some further reading about ListViews, including examples: http://www.vogella.com/tutorials/AndroidListView/article.html

这篇关于ArrayAdapter&LT; D​​ummyContent.DummyItem&GT;与android.R.layout.simple_list_item_activated_2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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