Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了自定义列表项到ListView android大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在玩这个列表活动教程:

http://developer.android.com/resources/tutorials/views/hello-listview.html@H_944_3@

它告诉你开始扩展List活动.@H_944_3@

by public class Main extends ListActivity {

这是基于对textview only布局进行充气.@H_944_3@

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://scheR_829_11845@as.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>

如果我想通过添加图像以及列表适配器上方的额外线性布局来更多地自定义布局,那么可以使用此方法 – 如果是这样,我该怎么做?@H_944_3@

解决方法

可以使用 SimpleAdapter.

这是一个例子:@H_944_3@

// Create the item mapping
    String[] from = new String[] { "title","description" };
    int[] to = new int[] { R.id.title,R.id.description };

现在“title”映射到R.id.title,“description”映射到R.id.description(在下面的XML中定义).@H_944_3@

// Add some rows
    List<HashMap<String,Object>> fillMaps = new ArrayList<HashMap<String,Object>>();

    HashMap<String,Object> map = new HashMap<String,Object>();
    map.put("title","First title"); // This will be shown in R.id.title
    map.put("description","description 1"); // and this in R.id.description
    fillMaps.add(map);

    map = new HashMap<String,"Second title");
    map.put("description","description 2");
    fillMaps.add(map);

    SimpleAdapter adapter = new SimpleAdapter(this,fillMaps,R.layout.row,from,to);
    setlistadapter(adapter);

这是相应的XML布局,这里名为row.xml:@H_944_3@

<LinearLayout xmlns:android="http://scheR_829_11845@as.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    <TextView
        android:id="@+id/description"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearancesmall" />
</LinearLayout>

我使用了两个TextView,但它对任何类型的视图都一样.@H_944_3@

大佬总结

以上是大佬教程为你收集整理的自定义列表项到ListView android全部内容,希望文章能够帮你解决自定义列表项到ListView android所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。