自定义列表项到ListView android

自定义列表项到ListView android,第1张

概述我一直在玩这个列表活动教程: http://developer.android.com/resources/tutorials/views/hello-listview.html 它告诉你开始扩展List活动. by public class Main extends ListActivity { 这是基于对textview only布局进行充气. <?xml version="1.0" enco 我一直在玩这个列表活动教程:

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

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

by public class Main extends ListActivity {

这是基于对textvIEw only布局进行充气.

<?xml version="1.0" enCoding="utf-8"?><TextVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:padding="10dp"    androID:textSize="16sp" ></TextVIEw>

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

解决方法 可以使用 SimpleAdapter.

这是一个例子:

// 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中定义).

// 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:

<linearLayout xmlns:androID="http://schemas.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,但它对任何类型的视图都一样.

总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1134637.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存