2012-04-03 12 views
0

私のXMLにボタンがあり、クリックするとTableLayoutの表示が切り替わります。これはXMLで、アンドロイドでtableLayoutの表示を切り替える機能

<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> 

それは日食に誤りはありませんが、ときに私これが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 

であり、これはJavaコードで、

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);  
    } 


} 

それが実行されていると、エラーが発生して強制的にアプリケーションを終了します。ありがとう。

+0

LogCatからスタックトレースを送信することができますか、それ以外のエラーが表示されますか?隠すテーブルのxmlを表示できますか? –

+0

XMLファイルを投稿しました。 LogCatは空ですが、 – rusty009

+0

システムに「エラーが発生しました」と表示され、強制終了すると、何らかの種類のキャッチされていない例外が発生したことが示されます。アプリケーションのlogcat出力はないかもしれませんが、すべてのフィルタリングをオフにするとエラーのlogcat出力があるはずです。 –

答えて

2

ShowAddOns()は、メソッドでターゲットビューを使用していない場合でも、ShowAddOns(View target)というView引数を取るようにしてください。

+0

完璧に動作します、ありがとう! – rusty009

+0

ようこそ。 upvoteを忘れないでください。 :) –

+0

@JonO 'onClick(View v)'にバインドしたくない場合はどうすればいいですか? 'MainActivity型のメソッドShowAddOns(View)はarguments()'には適用されません – user1480019

関連する問題