我的列表视图出现错误,我尝试了很多方法。我没明白。我错过了什么?我应该做哪些改变?如果我在没有对话的情况下尝试使用 arrayadapter 成功运行。我是android的新手。我提前非常感谢..
代码-
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
viewList = Topic.this.getLayoutInflater().inflate(R.layout.list_row, null);
dialogMarketList = new Dialog(Topic.this);
dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogMarketList.setContentView(viewList);
dialogMarketList.show();
Display newDisplay = getWindowManager().getDefaultDisplay();
int width = newDisplay.getWidth();
lvForDialog = (ListView) viewList.findViewById(R.id.ListView);
ArrayAdapter<String> adapter =(new ArrayAdapter<String>(Topic.this,R.layout.topic_row,R.id.childname, groupnamelist));
lvForDialog.setAdapter(adapter);
// lv = (ListView) findViewById(R.id.ListView);
// ArrayAdapter<String>adapter=new ArrayAdapter<String>(Topic.this,android.R.layout.simple_list_item_1,groupnamelist);
// lv.setAdapter(adapter);
lvForDialog.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id)
topic_row的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/childname"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
LogCat-
450: E/AndroidRuntime(1540): FATAL EXCEPTION: main
450: E/AndroidRuntime(1540): java.lang.IllegalStateException: ArrayAdapter requires
the resource ID to be a TextView
450: E/AndroidRuntime(1540): at
android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
450: E/AndroidRuntime(1540): at
android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
450: E/AndroidRuntime(1540): at
android.widget.AbsListView.obtainView(AbsListView.java:1430)
450: E/AndroidRuntime(1540): at
android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
01-16 17:11:09.450: E/AndroidRuntime(1540): at
android.widget.ListView.onMeasure(ListView.java:1127)
01-16 17:11:09.450: E/AndroidRuntime(1540): at
android.view.View.measure(View.java:8313)
01-16 17:11:09.450: E/AndroidRuntime(1540): at
android.widget.RelativeLayout.measureChild(RelativeLayout.java:566)
01-16 17:11:09.450: E/AndroidRuntime(1540): at
android.widget.RelativeLayout.onMeasure(RelativeLayout.java:381)
01-16 17:11:09.450: E/AndroidRuntime(1540): at
android.view.View.measure(View.java:8313)
01-16 17:11:09.450: E/AndroidRuntime(1540): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
450: E/AndroidRuntime(1540): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
E/AndroidRuntime(1540): at
android.view.View.measure(View.java:8313)
450: E/AndroidRuntime(1540): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
450: E/AndroidRuntime(1540): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
E/AndroidRuntime(1540): at
android.view.View.measure(View.java:8313)
450: E/AndroidRuntime(1540): at
android.view.ViewRoot.performTraversals(ViewRoot.java:839)
450: E/AndroidRuntime(1540): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
450: E/AndroidRuntime(1540): at
android.os.Handler.dispatchMessage(Handler.java:99)
450: E/AndroidRuntime(1540): at
android.os.Looper.loop(Looper.java:123)
450: E/AndroidRuntime(1540): at
android.app.ActivityThread.main(ActivityThread.java:3683)
450: E/AndroidRuntime(1540): at
java.lang.reflect.Method.invokeNative(Native Method)
450: E/AndroidRuntime(1540): at
java.lang.reflect.Method.invoke(Method.java:507)
450: E/AndroidRuntime(1540): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
450: E/AndroidRuntime(1540): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
450: E/AndroidRuntime(1540): at
dalvik.system.NativeStart.main(Native Method)
450: E/AndroidRuntime(1540): Caused by:
java.lang.ClassCastException: android.widget.ListView
450: E/AndroidRuntime(1540): at
android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:343)