0

我正在尝试将两个CheckBoxes组合成一个TableRow,以便它们并排放置。一旦我尝试加载视图,我的程序就会在运行时崩溃。

我以前将它们分别放在自己的行中,但想将它们更改为适合在同一行中。我搞砸了该android:layout_width功能,但无济于事。这是我为TableRow.

         <TableRow>
            <CheckBox 
                android:id="@+id/circleCloseCheck"
                android:text="@string/parameters_circle_close"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <CheckBox
                android:id="@+id/nwpCheck"
                android:text="@string/parameters_nwp_check"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </TableRow>

这是我的 LogCat ...

08-23 08:59:20.760: W/dalvikvm(27494): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-23 08:59:20.768: E/AndroidRuntime(27494): FATAL EXCEPTION: main
08-23 08:59:20.768: E/AndroidRuntime(27494): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.eti.commander/my.eti.commander.Parameters}: java.lang.ClassCastException: android.widget.CheckBox
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.os.Looper.loop(Looper.java:130)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.main(ActivityThread.java:3683)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at java.lang.reflect.Method.invokeNative(Native Method)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at java.lang.reflect.Method.invoke(Method.java:507)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at dalvik.system.NativeStart.main(Native Method)
08-23 08:59:20.768: E/AndroidRuntime(27494): Caused by: java.lang.ClassCastException: android.widget.CheckBox
08-23 08:59:20.768: E/AndroidRuntime(27494):    at my.eti.commander.Parameters.populateArrayLists(Parameters.java:534)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at my.eti.commander.Parameters.onCreate(Parameters.java:54)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-23 08:59:20.768: E/AndroidRuntime(27494):    ... 11 more

编辑 :

这是我的 Parameters.java 文件中第 534 行的信息。第 534 行是wattVarCurrentSpinner = (Spinner) findViewById( R.id.wattVarCurrentSpinner.

    wattVarCurrentRelayList = new ArrayList<String>();
    wattVarCurrentRelayList.add( "N/A" );
    for( int i = 1; i <= 100; i++ ) {
        double temp = (i/10.0);
        wattVarCurrentRelayList.add( String.valueOf( temp ) );
    }
    wattVarCurrentSpinner = (Spinner) findViewById( R.id.wattVarCurrentSpinner );
    if( RelayAPIModel.AppPrefsType.displayUnits.equals( "Relay" ) ) {
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentRelayList );
    } else if( RelayAPIModel.AppPrefsType.displayUnits.equals( "Protector" ) ) {
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentProtectorList );
    } else if( RelayAPIModel.AppPrefsType.displayUnits.equals( "Percent" ) ) {
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentPercentList );      
    } else {
        RelayAPIModel.AppPrefsType.displayUnits = "Relay";
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentRelayList );
    }
    wattVarCurrentAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    wattVarCurrentSpinner.setAdapter( wattVarCurrentAdapter );
4

2 回答 2

1

每个复选框中应该是 android:layout_width="wrap_content" ;您还应该将 android:layout_weight="1.0" 添加到每个复选框

完美的例子在这里:所以回答

于 2012-08-23T13:08:43.580 回答
1

我想您忘记为TableRow添加 layout_width 和 layout_height 还需要将复选框 layout_width 更改为“wrap_content”

    <TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <CheckBox
        android:id="@+id/circleCloseCheck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/parameters_circle_close" />

    <CheckBox
        android:id="@+id/nwpCheck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/parameters_nwp_check" />
</TableRow>
于 2012-08-23T13:10:08.570 回答