2010-11-18 3 views

답변

9

어쩌면 각 중 하나가 자신의 가시성을 전환 할 수 있습니다. 버튼을 클릭하면 표시되는 텍스트를 가져와 보이지 않는 텍스트에 적용한 다음 가시성을 바꿉니다.

+3

@MarvinLabs처럼

: +1, 그는 빠른했다) –

4

레이아웃에 둘 다있을 수 있으며 항상 둘 중 하나만 표시 할 수 있습니다. EditText 값이 변경되면 숨겨진 TextView를 업데이트하여 동기화하십시오.

+2

@ 부자 : 좋아, 당신은 내가 정직에서 생각하는 빠른 –

0

나는 결코 시도하지 못했지만 (아마도) EditText를 사용하고 TextView의 배경을 설정할 수 있습니다. 그런 다음 onfocus 변경하면 주어진 순간에보고 싶은 것을 바탕으로 배경을 바꿀 수 있습니다. 그것이 작동 있을지 나는 그것을 구현하고보고하려고합니다

67

... 
    <ViewSwitcher 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/my_switcher" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <TextView 
      android:id="@+id/clickable_text_view" 
      android:clickable="true" 
      android:onClick="TextViewClicked" 
      android:text="@string/some_value" /> 

     <EditText 
      android:id="@+id/hidden_edit_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/some_value" /> 
    </ViewSwitcher> 
... 

그럼 당신은 내가 가장에 생각 무엇

public void TextViewClicked() { 
    ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.my_switcher); 
    switcher.showNext(); //or switcher.showPrevious(); 
    TextView myTV = (TextView) switcher.findViewById(R.id.clickable_text_view); 
    myTV.setText("value"); 
} 
+0

:-)있어 그들 모두,이 대답이 최고였습니다. 그만큼 간단 해. 나는 호기심이 많다. 언제 이것을 사용해야합니까? 나는 그 문서를 읽었고, 그것은 애니메이션 형식의 것들에 대해 말한다. 그러나이 경우 그것을 사용하는 것이 좋습니다. 이 경우에는 사용하지 않는 이유가 무엇입니까? – Andy

+0

스위처보기는 멋지게 작동하며 애니메이션을 쉽게 추가 할 수 있습니다. – Patrick

+1

멋지지만'switcher' 선언에 여분의 공간을 추가하십시오 –

0

하여보기를 전환 할 수있는 ViewSwitcher를 사용하는 것이 가장 실제로 Framelayout 개념을 사용하십시오.

원래 레이아웃이 같은 FrameLayout이 내부

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
. 
. 
. 
</Linearlayout> 

같은 장소를 같은 보이는 것이다.

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
. 
. 
. 
</Linearlayout> 

<!-- The Magic is here --> 
<View 

    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
/> 



</FrameLayout> 

여기서 LinearLayout은 모든 EditText보기를 유지합니다. 또한 EditText View의 배경을 null로 만드는 것을 잊지 마십시오. 이

<EditText 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:id="@+id/editInp" 
     android:hint="@string/hello_world" 
     android:background="@null" 
     android:singleLine="true" 
     android:inputType="textCapWords"/> 

또는

<EditText 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:id="@+id/editInp" 
     android:hint="@string/hello_world" 
     android:background="@android:drawable/transparent" 
     android:singleLine="true" 
     android:inputType="textCapWords"/> 
관련 문제