好吧,我投降了,这个问题折磨了我一天啊!!!!!!
Andy韩 2010-10-17 01:44:43 各位高手帮我看看吧。我写的显示ListView的例子始终被显示出错。。。。我也查不出错误在哪。
我的Activity代码:
public class ShowAllItem extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showall);
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map1 = new HashMap<String, String>();
HashMap<String, String> map2 = new HashMap<String, String>();
HashMap<String, String> map3 = new HashMap<String, String>();
map1.put("user_name", "zhangsan");
map1.put("user_ip", "192.168.0.1");
map2.put("user_name", "zhangsan");
map2.put("user_ip", "192.168.0.2");
map3.put("user_name", "wangwu");
map3.put("user_ip", "192.168.0.3");
list.add(map1);
list.add(map2);
list.add(map3);
SimpleAdapter listAdapter = new SimpleAdapter(this, list,
R.layout.showallitem, new String[] { "user_name", "user_ip" },
new int[] { R.id.user_name,R.id.user_ip});
setListAdapter(listAdapter);
}
}
我的showall.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:drawSelectorOnTop="false"
android:scrollbars="vertical" />
</LinearLayout>
我的showallitem.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal" android:paddingLeft="10dip"
android:paddingRight="10dip" android:paddingTop="1dip"
android:paddingBottom="1dip">
<TextView android:id="@+id/user_name" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="10pt"
android:singleLine="true" />
<TextView android:id="@+id/user_ip" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="right"
android:textSize="10pt" />
</LinearLayout>
说明一点这些代码在另一个程序中就可以运行,我试过了,可是我放在我现在正在开发的程序中就不能运行了,不知道为什么,我还试过将这段代码放在一个按钮事件中去调用Activity的方法运行,还是不行。我也试过把自己的项目中的其他文件都删除就留下和ListView相关联的文件,还是不能运行。。而我看过报错,没说什么异常,就是说第几行出错了。。。。我很郁闷,这个问题搞了我一天。
我这一天都在忙着解决这个问题,还是没有用,我实在不知道该怎么办了。。。。。。。希望能有高人或者以前有过类似经历的人给我讲讲是怎么回事,我真的被这个问题打败了。。。
你们也可以把你们的邮箱发给我,我发给你们你们帮我看看,然后在给我讲讲,谢谢了~~~~~~~~~~~