2014-02-13 2 views
0

안녕하세요보기 버튼 부분은

나는 안드로이드에 새로운입니다. 많은 Buttons이 (가) 안드로이드에서 볼 수 있으며 다른 버튼을 클릭하여 부분적으로 보여주고 싶습니다.

+1

무엇'예 중 먼저 세에 대한 clicking' – Nambi

+0

에 의해 다음 버튼 쇼 다음 세 개의 버튼을 클릭 한 후 부분으로 그들에게 일부를 보여주는 것입니다. – Vaseph

+1

사용, VISIBLE 보이지 GONE 기능 – NagarjunaReddy

답변

0

나는 다음 코드를 작성하고 내 문제를 해결했다. 어쩌면 누구에게나 유용 할 수도 있습니다 next = (Button) findViewById (R.id.next); 다음.setOnClickListener (새 OnClickListener를() {

 @Override 
     public void onClick(View v) 
     { 
      if(i<movie_list.length-3) 
      { 
       movie_list[i].setVisibility(View.GONE); 
       movie_list[i+3].setVisibility(View.VISIBLE); 
       i++; 
      }else{ 
       Toast.makeText(getApplicationContext(), "That is the end of the buttons ", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 
1

사용 android:visibility="visible" 또는 android:visibility="gone" 또는 android:visibility="invisible"

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="91dp" 
    android:layout_toLeftOf="@+id/textView1" 
    android:text="Button" 
    android:visibility="visible" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/button1" 
    android:layout_alignLeft="@+id/textView1" 
    android:text="Button" 
    android:visibility="invisible" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/button2" 
    android:layout_alignBottom="@+id/button2" 
    android:layout_toRightOf="@+id/button2" 
    android:text="Button" 
    android:visibility="invisible" /> 
2

설정 버튼의 가시성에 GONE (버튼을 완전히 "제거"할 것이다 - 버튼 공간이 다른 위젯 사용할 수 있습니다) 또는 INVISIBLE (버튼의 뜻은 "투명되었다 "- 그 공간) 다른 위젯을 사용할 수 없습니다 :

View b = findViewById(R.id.button); 
b.setVisibility(View.GONE); 

또는 XML에 :

,451,515,
<Button ... android:visibility="gone"/> 

참고 문헌으로는 : LINK

+0

나는이 코드를했다. next = (Button) findViewById (R.id.next); \t \t next.setOnClickListener (new OnClickListener() {\t \t \t \t \t \t @Override \t \t \t 공개 무효 온 클릭 (뷰 V) \t \t \t { \t \t \t \t 경우 (전 movie_list.length를 <) \t \t \t \t { \t \t \t \t \t movie_list [i] .set 가시성 (View.GONE); \t \t \t \t movie_list [i + 3] .setVisibility (View.VISIBLE); \t \t \t \ti ++; \t \t \t \t한다} else {가 \t \t \t \t \t Toast.makeText (getApplicationContext는() "즉 버튼의 끝"Toast.LENGTH_SHORT) .show(); \t \t \t \t \t} \t \t \t \t }}); 하지만 마지막 버튼을 표시 한 후 다음 버튼을 클릭하면 "앱이 중지되었습니다"오류가 발생합니다. – Vaseph

+0

오케이 내가 실수를 바로 잡았습니다. – Vaseph

+0

네 스스로 해결할 수있는 좋은 .. :) – AndyBoy

1

하자 당신이 개 버튼이 말 : XML이 쓰기 : 당신이 button1을 클릭 할 때 : 당신의 한 OnCreate 방법에서

<Button android:id="@+id/btn1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Button 1"/> 

<Button android:id="@+id/btn2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="button 2" 
    android:layout_below="@+id/btn1" 
    android:visibility="invisible"/> 

이 쓰기 아래와 같이 버튼이 보이지 않는 확인 , button2가 나타납니다.

 Button btn1 = (Button)findViewById(R.id.btn1); 
    final Button btn2 = (Button)findViewById(R.id.btn2); 

    btn1.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      btn2.setVisibility(View.VISIBLE); 

     } 
    }); 

1
<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="91dp" 
    android:layout_toLeftOf="@+id/textView1" 
    android:text="Button" 
    android:visibility="gone" /> 


<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/button1" 
    android:layout_alignLeft="@+id/textView1" 
    android:text="Button" 
    android:visibility="gone" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/button2" 
    android:layout_alignBottom="@+id/button2" 
    android:layout_toRightOf="@+id/button2" 
    android:text="Button" 
    android:visibility="gone" /> 
  1. 먼저 모든 버튼을 갖는 위의 XML 레이아웃을 만들고 버튼이 때문에 초기에 사용하면 공간과 시간을 절약 기본적으로 레이아웃에서 공간을 차지하지 않기 때문에 GONE로 설정합니다.
  2. 이제 클릭 이벤트에 대한 코드에서이 버튼의 가시성을 VISIBLE으로 설정하면됩니다.

    가시성을 변경하는 단계 HashMap map = new HashMap(); map.put (R.id.button1, new Integer [] {R.id.button2, R.id.button3, R.id.button4});

공개 무효 온 클릭 (뷰 V) {

정수 [] = buttonsToShow map.get (R.id.v.getId());

경우 (buttonsToShow = NULL!) (INT 버튼 : buttonsToShow) 용 {

findViewById를 (버튼) .setVisibility (View.VISIBLE);

} }