2013-02-17 57 views
2

我对这个Android应用程序很新,有几个涉及onclick监听器的问题。Android Button Listerners

现在我在ScrollView中有一个表格,其中一列包含几个按钮。 我的目标是达到一个点,我可以点击一个按钮,然后第二个表会出现在第一个(与第一个相同的布局)旁边,但有一组不同的按钮。有人能指导我在正确的方向。

让我知道如果您有任何问题。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation='vertical' > 

<ScrollView 
android:layout_width="125dp" 
android:layout_height="200dp" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TableLayout android:id="@+id/table_right" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <TableRow android:id="@+id/row_1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <Button 
       android:id="@+id/Button_1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Button 1" 
       android:textSize="20dp" > 
      </Button> 
      </TableRow> 

     <TableRow android:id="@+id/row_2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

       <Button android:id="@+id/Button_2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button 2" 
        android:textSize="25dp" > 
       </Button> 
      </TableRow> 

     <TableRow android:id="@+id/row_3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

       <Button android:id="@+id/Button_3" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Button 3" 
        android:textSize="25dp" > 
       </Button> 
      </TableRow> 

     <TableRow android:id="@+id/row_4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

       <Button android:id="@+id/Button_4" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Button 4" 
        android:textSize="25dp" > 
       </Button> 
      </TableRow> 

      <TableRow android:id="@+id/row_5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

       <Button android:id="@+id/Button_5" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Button 5" 
        android:textSize="25dp" > 
       </Button> 
      </TableRow> 

      <TableRow android:id="@+id/row_6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

       <Button android:id="@+id/Button_6" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Button 6" 
        android:textSize="25dp" > 
       </Button> 
      </TableRow> 

    </TableLayout> 
     </LinearLayout> 
      </ScrollView> 
      </LinearLayout> 
+1

是的请列出您的代码,以便我们可以帮您 – 2013-02-17 17:36:43

+0

设置标签的按钮和处理它。 – 2013-02-17 17:57:15

+0

我加了我到目前为止的所有 – user31610 2013-02-17 18:19:52

回答

1

切换可见和不可见的表将我会建议你使用这个跟随我在这里的例子: -

  boolean visible = true; 
     private void showHide() { 

      if (visible) { 
      if(table1.getVisibility() == View.Invisible); { 
       table1.setVisibility(View.Visible) 
      } 
      }else table1.setVisibility(View.Invisible); 

      visible = !visible; 
     } 

,并在你的buttonsetOnClickListener添加showHide();现在当你点击按钮时,它会显示table1,当你再次点击它会隐藏它。希望对你有所帮助。

+0

好的,谢谢这是在.java文件 – user31610 2013-02-17 21:04:22

+0

这是java?在android platoform下。 – k0sh 2013-02-18 04:38:01

1

在布局XML文件,创建两个表......但设置第二个表的可见性“水涨船高”。 GONE的可视性意味着它甚至不会占用布局中的任何空间。

我假设你知道如何按下按钮时执行一些代码(如果没有,请查看onclicklistener或android:onClick xml快捷方式)。当按下适当的按钮时,将第二张桌子的可见性设置为可见,它会出现。

+0

所以我可能会看到一张桌子,然后用onclicklisterner – user31610 2013-02-17 18:21:07

+0

请问有没有办法让第一张桌子变暗并让第二张桌子变暗 – user31610 2013-02-17 18:31:13