Ich habe eine Schaltfläche in meinem XML, die, wenn geklickt wird, schaltet die Sichtbarkeit meiner TableLayout. Dies ist der XML,Funktion zum Umschalten der Sichtbarkeit von tableLayout in Android funktioniert nicht
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/LayoutAddOns"
android:orientation="vertical" >
<!-- Accordion button -->
<Button
android:id="@+id/DisplayAddOns"
android:layout_width="335dp"
android:layout_height="35dp"
android:drawableLeft="@drawable/rarrow"
android:onClick="ShowAddons"
android:text="AddOns (Optional)" />
<!-- Table for add ons -->
<TableLayout
android:id="@+id/tableAddOns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<CheckBox
android:id="@+id/CheckGalleryPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Gallery Plus"
android:textSize="14sp" />
<CheckBox
android:id="@+id/CheckSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Subtitle"
android:textSize="14sp" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/CheckDesigner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Designer"
android:textSize="14sp" />
<CheckBox
android:id="@+id/CheckSupersize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Supersize"
android:textSize="14sp" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/CheckScheduled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Scheduled"
android:textSize="14sp" />
<CheckBox
android:id="@+id/CheckInternationalVisibility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="International Visibility"
android:textSize="14sp" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/CheckBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Bold"
android:textSize="14sp" />
<CheckBox
android:id="@+id/CheckHighlight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Highlight"
android:textSize="14sp" />
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/CheckFeaturedList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Featured List"
android:textSize="14sp" />
<CheckBox
android:id="@+id/CheckFeaturedPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Featured Plus"
android:textSize="14sp" />
</TableRow>
</TableLayout>
</LinearLayout>
Dies sind die Daten von LogCat,
04-03 01:21:52.891: D/AndroidRuntime(408): Shutting down VM
04-03 01:21:52.891: W/dalvikvm(408): threadid=1: thread exiting with uncaught exception (group=0x40014760)
04-03 01:21:52.911: E/AndroidRuntime(408): FATAL EXCEPTION: main
04-03 01:21:52.911: E/AndroidRuntime(408): java.lang.IllegalStateException: Could not find a method ShowAddons(View) in the activity class toggler.state.TogglerActivity for onClick handler on view class android.widget.Button with id 'DisplayAddOns'
04-03 01:21:52.911: E/AndroidRuntime(408): at android.view.View$1.onClick(View.java:2670)
04-03 01:21:52.911: E/AndroidRuntime(408): at android.view.View.performClick(View.java:3110)
04-03 01:21:52.911: E/AndroidRuntime(408): at android.view.View$PerformClick.run(View.java:11934)
04-03 01:21:52.911: E/AndroidRuntime(408): at android.os.Handler.handleCallback(Handler.java:587)
04-03 01:21:52.911: E/AndroidRuntime(408): at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 01:21:52.911: E/AndroidRuntime(408): at android.os.Looper.loop(Looper.java:132)
04-03 01:21:52.911: E/AndroidRuntime(408): at android.app.ActivityThread.main(ActivityThread.java:4123)
04-03 01:21:52.911: E/AndroidRuntime(408): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 01:21:52.911: E/AndroidRuntime(408): at java.lang.reflect.Method.invoke(Method.java:491)
04-03 01:21:52.911: E/AndroidRuntime(408): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-03 01:21:52.911: E/AndroidRuntime(408): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-03 01:21:52.911: E/AndroidRuntime(408): at dalvik.system.NativeStart.main(Native Method)
04-03 01:21:52.911: E/AndroidRuntime(408): Caused by: java.lang.NoSuchMethodException: ShowAddons [class android.view.View]
04-03 01:21:52.911: E/AndroidRuntime(408): at java.lang.ClassMembers.getConstructorOrMethod(ClassMembers.java:235)
04-03 01:21:52.911: E/AndroidRuntime(408): at java.lang.Class.getMethod(Class.java:904)
04-03 01:21:52.911: E/AndroidRuntime(408): at android.view.View$1.onClick(View.java:2663)
04-03 01:21:52.911: E/AndroidRuntime(408): ... 11 more
und dies ist der Java-Code,
public void ShowAddons(){
int TableId = R.id.tableAddOns;
TableLayout TableVisibility = (TableLayout)findViewById(TableId);
if(TableVisibility.getVisibility() == View.VISIBLE)
{
TableVisibility.setVisibility(View.GONE);
}
else
{
TableVisibility.setVisibility(View.VISIBLE);
}
}
Es keine Fehler in Eclipse hat, aber als ich führe es aus, es sagt, es ist ein Fehler aufgetreten und erzwingt die Anwendung. Vielen Dank.
Können Sie den Stack-Trace von LogCat aus veröffentlichen oder uns anderweitig mitteilen, welchen Fehler Sie bekommen? Können Sie uns das XML für die Tabelle anzeigen, die Sie ausblenden möchten? –
Hat die XML-Datei gesendet. Der LogCat ist leer, obwohl – rusty009
Wenn Sie sagen, dass das System Ihnen sagt, dass "ein Fehler aufgetreten ist" und Force schließt, ist dies ein Hinweis darauf, dass eine Art von nicht abgefangener Ausnahme aufgetreten ist. Möglicherweise gibt es keine Logcat-Ausgabe für Ihre Anwendung, aber es sollte eine Logcat-Ausgabe für den Fehler angezeigt werden, wenn Sie die gesamte Filterung deaktivieren. –