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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)