このチュートリアルを実行して、画像を含むカスタムリストを作成しましたが、うまくいきました(ところで、カスタムリストのレイアウトをlinearLayoutに変更しました。コードは次のとおりです:
<?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="vertical" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
しかし、私が欲しいのは、imageView (id=icon) と textView (id=title),sth の位置を次のように入れ替えることです:
<?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="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
問題は、アプリの実行時に強制終了することです.JavaコードのconvertViewでsthが間違っていることは知っていますが、それが何であるかはわかりません.助けてくれてありがとう
ここに私のLogCatがあります:
04-19 12:06:19.121: I/Process(747): Sending signal. PID: 747 SIG: 9
04-19 12:06:27.611: D/AndroidRuntime(773): Shutting down VM
04-19 12:06:27.621: W/dalvikvm(773): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-19 12:06:27.621: E/AndroidRuntime(773): Uncaught handler: thread main exiting due to uncaught exception
04-19 12:06:27.651: E/AndroidRuntime(773): java.lang.ClassCastException: android.widget.ImageView
04-19 12:06:27.651: E/AndroidRuntime(773): at com.myapp.adapters.CustomListViewAdapter.getView(CustomListViewAdapter.java:43)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.AbsListView.obtainView(AbsListView.java:1274)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.ListView.measureHeightOfChildren(ListView.java:1147)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.ListView.onMeasure(ListView.java:1060)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.View.measure(View.java:7964)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.View.measure(View.java:7964)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.View.measure(View.java:7964)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.View.measure(View.java:7964)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.View.measure(View.java:7964)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.ViewRoot.performTraversals(ViewRoot.java:763)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.os.Looper.loop(Looper.java:123)
04-19 12:06:27.651: E/AndroidRuntime(773): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-19 12:06:27.651: E/AndroidRuntime(773): at java.lang.reflect.Method.invokeNative(Native Method)
04-19 12:06:27.651: E/AndroidRuntime(773): at java.lang.reflect.Method.invoke(Method.java:521)
04-19 12:06:27.651: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-19 12:06:27.651: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-19 12:06:27.651: E/AndroidRuntime(773): at dalvik.system.NativeStart.main(Native Method)
04-19 12:06:27.671: I/dalvikvm(773): threadid=7: reacting to signal 3
04-19 12:06:28.071: I/dalvikvm(773): Wrote stack trace to '/data/anr/traces.txt'
04-19 12:06:29.661: I/Process(773): Sending signal. PID: 773 SIG: 9