【发布时间】:2012-12-18 11:40:32
【问题描述】:
我创建了一个 ListActivity,将数据库中的数据放入游标,然后将它们添加到 ArrayLisy>,然后将其发布到 Simple adatper。
一切正常,但显示一个空白屏幕。
代码如下:
public class Cities extends ListActivity {
ListView listV ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.only_text_listview);
//getting the database opened from the adapter
CitiesAdapter mDbHelper = new CitiesAdapter(this);
mDbHelper.createDatabase();
mDbHelper.open();
// getting cursor from data base
Cursor testdata = mDbHelper.getTestData();
ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String,String>>();
if(testdata.moveToFirst()){
HashMap<String, String> map = new HashMap<String, String>();
do{
Log.d("Cursor", testdata.getString(2));
map.put("name_en", testdata.getString(2));
}while(testdata.moveToNext());
data.add(map);
}
String[] from = {"name_en"};
int[] to = {R.id.only_text_lv};
SimpleAdapter SA = new SimpleAdapter(this, data, R.layout.only_text_listview , from, to);
this.setListAdapter(SA);
mDbHelper.close();
}
xml 文件:
only_text_list.xml
<ListView
android:id ="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
/>
only_text_lv.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id ="@+id/only_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
/>
【问题讨论】:
-
能否提供activity的xml布局文件?
-
就是完整的布局文件。
-
是的,这是我应用中的完整布局
标签: android android-listview listactivity simpleadapter