是这样的 我要从数据库中取出来一些数据 放到 map中 然后再将map放到list中 再把list放到屏幕上 主要是为了实现从数据库中取出的数据可点击状态 开始的时候我创建了一个实验工程 数据库中有2个列 id name 然后取出id 和 name 没有任何问题 代码是这样的:
public class sqliteActivity extends ListActivity {
String name;
String id;
    TextView user_name;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

user_name = (TextView)findViewById(R.id.user_id);
//user_name.setFocusable(true);
sqliteOpenHelper helper = new sqliteOpenHelper(sqliteActivity.this,
"sqliteTest");
SQLiteDatabase sqlite = helper.getReadableDatabase();
Cursor cursor = sqlite.query("user", new String[] { "id", "name" },
null, null, null, null, null);
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
while (cursor.moveToNext()) {
name = cursor.getString(cursor.getColumnIndex("name"));
id = cursor.getString(cursor.getColumnIndex("id"));
HashMap<String, String> map = new HashMap<String, String>();
map.put("user_id", id);
map.put("user_name", name);
System.out.println(map.values());//输出map中的值 看看插进去没有
list.add(map);
if(list.isEmpty()){System.out.println("list is empty");}//判断list是不是空的 作为验证
else{System.out.println("list is not empty");}
System.out.println(id);//输出id 和 name
System.out.println(name);
}
SimpleAdapter listAdapter = new SimpleAdapter(this, list,
R.layout.users, new String[] { "user_id", "user_name" },
new int[] { R.id.user_id, R.id.user_name });
setListAdapter(listAdapter);
}这个就不多说了 运行正常 下边开始问题 我如法炮制 在另一个工程中也创建了一个表 有6个列 id sign name latitude longitude description, 但是我不需要显示6个 我只需要显示name就可以了 但是我在代码中为了不出错 和上边一样 显示了id和name 代码如下:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
dataBaseHelper hereami_helper = new dataBaseHelper(listview.this, "hereamiTest");
SQLiteDatabase sqlite = hereami_helper.getReadableDatabase();
Cursor cursor = sqlite.query("hereami_table", new String[] {"id", "name" },
null, null, null, null, null);
ArrayList<HashMap<String, String>> hereami_list = new ArrayList<HashMap<String, String>>();
while (cursor.moveToNext()) {
    id = cursor.getString(cursor.getColumnIndex("id"));
            name = cursor.getString(cursor.getColumnIndex("name"));


HashMap<String, String> map = new HashMap<String, String>();
map.put("id", id);
map.put("name", name);
System.out.println(map.values());
hereami_list.add(map);
if(hereami_list.isEmpty()){System.out.println("list is empty");}
else{System.out.println("list is not empty");}
System.out.println(id);
System.out.println(name);
}
SimpleAdapter hereami_listAdapter = new SimpleAdapter(this, hereami_list,
R.layout.listview_hashmap, new String[] { "id","name" },
new int[] {R.id.id,R.id.name });
setListAdapter(hereami_listAdapter);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
if (id == 0) {
Toast.makeText(listview.this, name+" is checked",
Toast.LENGTH_LONG).show();
} else if (id == 1) {
Toast.makeText(listview.this, name+" is checked", Toast.LENGTH_LONG)
.show();
} else if (id == 2) {
Toast.makeText(listview.this, "wangwu is checked",
Toast.LENGTH_LONG).show();
}else if (id == 3) {
Toast.makeText(listview.this, "zhongguoyinhang is checked",
Toast.LENGTH_LONG).show();
}
}
}我在adb shell中向表插入了2行数据 但是在手机屏幕上 只能看到一行0靠左边 名字没出来 下一行1 名字也没出来 里边的所有System.out输出都没输出出来 但是确实进入了while啊!要不0和1是哪来的?!非常的不解! 开始以为是名字太长了显示不下 但是插入了 个名字短的也不输出 但是在点击了以后 Toast还是会输出2行对应的名字 非常费解! 下边是list对应的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingLeft="10dip"
android:paddingRight="10dip" android:paddingTop="1dip"
android:paddingBottom="1dip">
<TextView android:id="@+id/id" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="left"
android:textSize="10pt" android:singleLine="true" />
<TextView android:id="@+id/name" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="right"
android:singleLine="true" android:textSize="10pt" android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" />
</LinearLayout>希望高手解答