0
A
回答
0
您可以定义一个兼容TextView和Button的Layout。 在运行时只需设置那些setVisibility(Visibility.VISIBLE)
和其他setVisibility(Visibility.INVISIBLE)
1
你所要做的是一个不好的设计。
隐藏按钮并显示一个TextView。
0
您可以使用ViewSwitcher这是非常最好的技术 这里只是改变的EditText用按钮简单:)
如
XML
<ViewSwitcher
android:id="@+id/my_switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/clickable_text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="TextViewClicked"
android:text="abc"
android:textColor="@color/white"
android:textSize="16sp" >
</TextView>
<EditText
android:id="@+id/hidden_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="12"
android:text="12"
android:textColor="@color/white"
android:textSize="16sp" >
</EditText>
</ViewSwitcher>
JAVA
ViewSwitcher my_switcher;
my_switcher = (ViewSwitcher) findViewById(R.id.my_switcher);
TextView profile_name = (TextView) findViewById(R.id.clickable_text_view);
profile_name.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
TextViewClicked();
}
});
TextViewClicked()
public void TextViewClicked() {
my_switcher.showNext(); //or switcher.showPrevious();
TextView myTV = (TextView) my_switcher.findViewById(R.id.clickable_text_view);
myTV.setText("value");
}
希望它能帮助
是的,这就是我打算做的。我想知道的是,我怎样才能在XML中的同一位置声明TextView和Button? – Chris 2010-06-04 06:25:49
在FrameLayout中保留两个视图,并根据您的需要使特定视图不可见/消失。 – Karan 2010-06-04 06:38:23