我想以ListView
基本格式编写一个,但出现错误:
UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
和:
androidview.LayoutInfalater.inflate(LayoutInflater.java: some numbers....like 720,658...so on)
我知道应该在适配器类中做一些事情:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
RelativeLayout rv = new RelativeLayout(c);
TextView tv = new TextView(c);
TextView tv1 = new TextView(c);
ImageView imgv = new ImageView(c);
tv.setText(s[position]);
tv1.setText(i[position]);
imgv.setImageResource(d[position]);
rv.addView(tv);
rv.addView(tv1);
rv.addView(imgv);
return rv;
}
我应该怎么做才能解决问题
LOGCAT:
02-20 16:40:24.967: E/Trace(1715): error opening trace file: No such file or directory (2)
02-20 16:40:25.819: W/ResourceType(1715): No package identifier when getting value for resource number 0x000020d0
02-20 16:40:25.819: D/AndroidRuntime(1715): Shutting down VM
02-20 16:40:25.819: W/dalvikvm(1715): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
02-20 16:40:25.857: E/AndroidRuntime(1715): FATAL EXCEPTION: main
02-20 16:40:25.857: E/AndroidRuntime(1715): android.content.res.Resources$NotFoundException: String resource ID #0x20d0
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.content.res.Resources.getText(Resources.java:229)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.TextView.setText(TextView.java:3620)
02-20 16:40:25.857: E/AndroidRuntime(1715): at com.example.systemzap2.adapt.getView(adapt.java:59)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.AbsListView.obtainView(AbsListView.java:2271)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.ListView.onMeasure(ListView.java:1156)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.View.measure(View.java:15172)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.View.measure(View.java:15172)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.View.measure(View.java:15172)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.View.measure(View.java:15172)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-20 16:40:25.857: E/AndroidRuntime(1715): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.View.measure(View.java:15172)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.Choreographer.doFrame(Choreographer.java:525)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.os.Handler.handleCallback(Handler.java:615)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.os.Handler.dispatchMessage(Handler.java:92)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.os.Looper.loop(Looper.java:137)
02-20 16:40:25.857: E/AndroidRuntime(1715): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-20 16:40:25.857: E/AndroidRuntime(1715): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 16:40:25.857: E/AndroidRuntime(1715): at java.lang.reflect.Method.invoke(Method.java:511)
02-20 16:40:25.857: E/AndroidRuntime(1715): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-20 16:40:25.857: E/AndroidRuntime(1715): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-20 16:40:25.857: E/AndroidRuntime(1715): at dalvik.system.NativeStart.main(Native Method)