我有一个水平的Listview。它工作正常。我的ArrayList eList将显示一个ListView穿过屏幕。那很棒。我的问题是,eList有多行,这意味着eList可能是飞机,汽车和船只,或无限数量的对象。目前,这个水平ListView将只显示数据库中的所有类型的飞机或汽车或船只。根据多少个对象类型(飞机,汽车,船,炸玉米饼,人),如何显示多个或无数个hListViews垂直垂直显示屏幕。如何使用多个HorizontalListView填充布局
活性
HorizontalListView hListView = (HorizontalListView) findViewById(R.id.hlistview1);
hListView.setAdapter(new ItemAdapter());
ArrayList<HashMap<String, String>> eList = controller.getAllts();
ListAdapter adapter = new SimpleAdapter(Su.this,eList,R.layout.view_m_ts, images, ins);
hListView.setAdapter(adapter);
数据库
public ArrayList<HashMap<String, String>> getAllts() {
ArrayList<HashMap<String, String>> List3;
List3 = new ArrayList<HashMap<String, String>>();
String selectQuery3 = "SELECT DISTINCT * FROM INV where p2 IS NOT NULL ORDER BY p2 COLLATE NOCASE ASC";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor3 = database.rawQuery(selectQuery3, null);
HashMap<String, String> map = new HashMap<String, String>();
if (cursor3.moveToFirst()) {
do {
map.put("iImageL", cursor3.getString(13));
map.put("p2", cursor3.getString(2));
map.put("se2", cursor3.getString(10));
map.put("te", cursor3.getString(17));
List3.add(map);
} while (cursor3.moveToNext());
}
close();
return List3;
}
以XML
<LinearLayout
android:id="@+id/LinearViewa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:orientation="vertical" >
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/hlistview1"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_weight=".1"
android:background="#000000" />
</LinearLayout>
我的不好。我建议的编辑是错误的。我没有注意到这一行 - >'List3.add(map);'。为什么不创建自定义对象并使用对象的ArrayList,而不是使用HashMap的ArrayList?还是有什么特别的理由,你正在使用一个ArrayList的HashMaps? – iRuth 2015-01-27 15:30:18
基本上我有人,地方和事物。我可以在屏幕上用可以是蓝色人,绿色人等等的地方或地点或事物填充屏幕。我的问题是我想要一排人,然后是一排地下,一排地下,等等。我发现我可以通过使用INV中的idnumber来做到这一点,然后告诉Activity在int idnumber上创建另一个HorizontalListView基础,但必须有更简单的方法。 – SmulianJulian 2015-01-27 15:58:41
如果我正确理解你,你当前的实现是一个水平滚动的列表视图,是否正确?你想要那个列表视图有3行,每个行都水平滚动,是否正确? – iRuth 2015-01-27 16:38:27