界面显示两个ListView

时间:2023-03-09 03:41:28
界面显示两个ListView

1.List界面布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:id="@+id/titleRelativeLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/title_height"
android:background="@color/title_background"
android:orientation="horizontal">
<ImageView
android:id="@+id/backImage"
android:src="@drawable/return_key_p"
android:layout_width="wrap_content"
android:layout_height="@dimen/title_height"
android:layout_marginLeft="@dimen/button_left"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/titleName"
android:layout_width="match_parent"
android:layout_height="@dimen/title_height"
android:text="Terminal Information"
android:textSize="@dimen/title_size"
android:textColor="@color/white"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="horizontal">
<ListView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@color/background"
android:dividerHeight="@dimen/interval"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout> 2.List_Items界面布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/terminalInfoLeft"
android:layout_width="match_parent"
android:layout_height="@dimen/list_height"
android:layout_weight="1"
android:textSize="@dimen/text_size1"
android:textColor="@color/black"
android:layout_marginLeft="@dimen/horizontal_interval"
android:gravity="center_vertical" />
<TextView
android:id="@+id/terminalInfoRight"
android:layout_width="match_parent"
android:layout_height="@dimen/list_height"
android:layout_weight="1"
android:gravity="center_vertical|right"
android:layout_marginRight="@dimen/horizontal_interval"
android:textSize="@dimen/text_size2"
android:textColor="@color/terminal_information" />
</LinearLayout>

3.两个ListView显示数据

public final class TerminalInformation {

    public static final String[][] DATA={
{"SN:","Serial Number"},
{"esSN:","Extended Seral Number"},
{"PED Ver:","PED Version"},
{"Term Info:","Terminal Information"},
{"APP Ver:","Application Version"}
};
} 4.设置适配器 final ListView listView1= (ListView)findViewById(R.id.list1);
List<Map<String, Object>> listItems=new ArrayList<Map<String,Object>>();
for (int i = 0; i < TerminalInformation.DATA.length; i++) {
Map<String, Object> listItem=new HashMap<String,Object>();
listItem.put("leftdata", TerminalInformation.DATA[i][0]);
listItem.put("rightdata", TerminalInformation.DATA[i][1]);
listItems.add(listItem);
}
SimpleAdapter simpleAdapter = new SimpleAdapter(this,listItems,R.layout.terminal_information,new String[]{"leftdata","rightdata"},new int[]{R.id.terminalInfoLeft,R.id.terminalInfoRight});
listView1.setAdapter(simpleAdapter);