我正在嘗試更改listview文本大小(默認情況下它看起來非常大)並且正在運行到錯誤中。我認爲這個想法是給列表視圖分配一個文本視圖並更改該文本視圖的屬性,但我開始認爲我正在以這種錯誤的方式進行。如果有人不介意看看我做錯了什麼,我將不勝感激。提前致謝!在android中更改列表視圖的文字大小
以下是錯誤:
12-03 21:59:26.894 24751-24751/my.obd2connector E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: my.obd2connector, PID: 24751
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.obd2connector/my.obd2connector.MyCar}: java.lang.ClassCastException: android.widget.ArrayAdapter cannot be cast to android.widget.TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.ArrayAdapter cannot be cast to android.widget.TextView
at my.obd2connector.MyCar.fillList(MyCar.java:120)
at my.obd2connector.MyCar.onStart(MyCar.java:92)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1189)
at android.app.Activity.performStart(Activity.java:5436)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
這裏是填充在那裏我試圖改變大小和顏色的列表視圖代碼:
public void fillList() {
carList.add(make + " " + model + "\n" + vin);
mylistAdapter = new ArrayAdapter<String>(MyCar.this, android.R.layout.simple_list_item_single_choice, carList);
mylistView.setAdapter(mylistAdapter);
TextView tv = (TextView)mylistView.getAdapter();
tv.setTextColor(Color.RED);
tv.setTextSize(12);
mylistAdapter.notifyDataSetChanged();
}
您正在使用的適配器? – 2014-12-04 04:03:04
其中:public ArrayAdapter mylistAdapter;我需要這個來填充字符串的ListView。 –
Shawn
2014-12-04 04:03:58