在ListView乘textviews [英] Multiply textviews in a listview

查看:159
本文介绍了在ListView乘textviews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有2文本视图的每一行中,基本上是一个标题,然后将其下面的描述。
我把每个视图中的每一行中的文本怎么办?

There are 2 text views in each row, basically a Title and then a description underneath it. How do I set the text of each view within each row?

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRoot = inflater.inflate(R.layout.frag_settings, container, false);

        mItems = getResources().getStringArray(R.array.setting_items);
        mItemDescription = getResources().getStringArray(R.array.setting_item_descriptions);

        mItemListView = (ListView) mRoot.findViewById(R.id.lvMainListView);

        ArrayAdapter<String> lvRowTitle = new ArrayAdapter<String>(getActivity(), 
                 R.layout.setting_twolinetext_checkbox, R.id.tvRowTitle,
                mItems);

        mItemListView.setAdapter(lvRowTitle);

        ArrayAdapter<String> lvRowDesc = new ArrayAdapter<String>(getActivity(), 
                R.layout.setting_twolinetext_checkbox, R.id.tvRowDesc,
                mItemDescription);

       mItemListView.setAdapter(lvRowDesc);

        return mRoot;
    }

看来我只能做一个文本视图或其他与我的设置。我敢肯定有一种方法。由于提前!

It seems I can only do one text view or another with my setup. Im sure there is a way. Thanks ahead of time!

推荐答案

您可以使用内置两个项目的ListView 。下面是一个简单的例子:

You can use the built in two item ListView. Here is a quick example:

List<Map<String, String>> data = new ArrayList<Map<String, String>>();

Map<String, String> dataMap = new HashMap<String, String>(2);
dataMap.put("Item1", item1Str);
dataMap.put("Item2", item2Str);
data.add(dataMap);

dataMap = new HashMap<String, String>(2);
dataMap.put("Item1", item1Str);
dataMap.put("Item2", item2Str);
data.add(dataMap);

SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), 
                                          data,
                                          android.R.layout.simple_list_item_2, 
                                          new String[] { "Item1", "Item2" }, 
                                          new int[] { android.R.id.text1, android.R.id.text2 });

listView.setAdapter(adapter);

或者你也可以让自己的布局资源文件,并替换android.R与你定制的资源属性。

Or you can make your own layout resource files and replace the android.R attributes with your custom made resources.

这篇关于在ListView乘textviews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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