android List实现表格

来源:互联网 发布:php程序员职业规划 编辑:程序博客网 时间:2024/06/06 02:19
<strong><span style="font-size:14px;">布局文件:</span><span style="font-size:24px;"> </span></strong>
   <LinearLayout        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:orientation="vertical" >        <include layout="@layout/listview_item_title" />        <ListView            android:id="@+id/list_DataQuery_view"            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1"            android:divider="@null"            android:listSelector="#00000000"            android:overScrollMode="never" >        </ListView>    </LinearLayout>
<strong><span style="font-size:18px;"></span></strong>
<pre name="code" class="html"><strong><span style="font-size:18px;">listview_item_title布局文件:</span></strong>
<strong><span style="font-size:18px;"></span></strong>
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/listview_item_title"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="horizontal" ></TableLayout>
Activity加载代码:
<pre name="code" class="java">public class Simple extends BaseActivity {private AnyItemsListViewAdapter adapter;private List<MyTitleSet> titleList = new ArrayList<MyTitleSet>();private List<Map<String, String>> dataSource = new ArrayList<Map<String, String>>();@Overrideprotected void initView() {// TODO Auto-generated method stubsetContentView(R.layout.simple);
<span style="white-space:pre"></span>/**
<span style="white-space:pre"></span>a标志
<span style="white-space:pre"></span>a2表头名称
<span style="white-space:pre"></span>*/this.titleList.add(new MyTitleSet("a", "a2", true));this.titleList.add(new MyTitleSet("b", "b2", true));this.titleList.add(new MyTitleSet("c", "c2", true));for (int i = 0; i < 100; i++) {Map<String, String> a = new HashMap<String, String>();a.put("a", String.valueOf(i * 1));a.put("b", String.valueOf(i * 2));a.put("c", String.valueOf(i * 3));dataSource.add(a);}ListView view = (ListView) findViewById(R.id.activity_showdetail_listview);adapter = new AnyItemsListViewAdapter(Simple.this, dataSource,titleList, R.id.listview_item_title);view.setAdapter(adapter);}}





0 0