我在ListActivity 使用 ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) 时出现异常,logcat捕捉的到的是android.widget.ArrayAdapter.createViewFromResource 这个接口在实例化view的时候出现了异常。HelloListView.java 代码如下:public class HelloListView extends ListActivity {
String[] COUNTRIES = new String[] {
"a",
"b",
"c"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); /**这一句调用出错**/
setListAdapter(new ArrayAdapter<String>(this, R.layout.resource_id, R.layout.textviewres_id,COUNTRIES));
}
}
第二个参数对应的resource_id.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"
>
<TextView
android:text="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>第三个参数对应的textviewres_id.xml<?xml version="1.0" encoding="utf-8"?>
<!-- This file defines the layout for each item that will be placed in the ListView -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:text="abc"
android:color="#aa0000"
>
</TextView>
String[] COUNTRIES = new String[] {
"a",
"b",
"c"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); /**这一句调用出错**/
setListAdapter(new ArrayAdapter<String>(this, R.layout.resource_id, R.layout.textviewres_id,COUNTRIES));
}
}
第二个参数对应的resource_id.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"
>
<TextView
android:text="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:text="3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>第三个参数对应的textviewres_id.xml<?xml version="1.0" encoding="utf-8"?>
<!-- This file defines the layout for each item that will be placed in the ListView -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:text="abc"
android:color="#aa0000"
>
</TextView>
解决方案 »
- android开发时遇到的错误
- android平台下的手机重力感应分析
- opengl es 开发获取资源失败
- 请教--android调用webservice时,httptransportse.call/AndroidHttpTransport 很慢,是什么原因啊?谢谢啦
- 图片内存溢出 开源TouchGallery使用
- 安卓链接网络问题,4.0无法链接
- 一个本科211的大四学生应该怎么找android的工作?
- 安卓App中网页链接调用拨号不管用的问题。。
- 萌新求救girdview
- 隐藏了虚拟键 但是在弹出popwindow的时候 虚拟键又自动出现了,怎么解决?
- 大家都来看一看,一个简单的调用问题!
- android 如何显示表格数据(从word里读取的表格)
恩,这样是可以的,已经实验过了,然后我尝试修改,所以调用ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)这个构造方法