Android - конвертировать кнопку в TextView во время выполнения - PullRequest
0 голосов
/ 04 июня 2010

Можно ли конвертировать Button в TextView по щелчку во время выполнения?

Спасибо, Крис

Ответы [ 3 ]

1 голос
/ 04 июня 2010

То, что вы пытаетесь сделать, это плохой дизайн.

Скрыть кнопку и показать вместо этого TextView.

0 голосов
/ 10 марта 2016

вы можете использовать ViewSwitcher, который является самым лучшим методом Здесь просто измените текст редактирования кнопкой Simple :)

* 1003 например *

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

Надеюсь, это поможет

0 голосов
/ 04 июня 2010

Вы можете определить макет, который содержит и TextView, и кнопку. Во время выполнения просто установите один setVisibility(Visibility.VISIBLE), а другой setVisibility(Visibility.INVISIBLE)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...