您好,我正在尝试使用 a在 and和 anviewswitcher
之间来回切换。我的视图从. 但不会切换回来。这是我的:TextView
EditText
edittext
textview
xml
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/noteItemVS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="@+id/noteItemTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="textview"
android:textAlignment="center" />
<EditText
android:id="@+id/noteItemEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="edittext"
android:textAlignment="center" />
</ViewSwitcher>
我的切换代码是:
protected void switchViews(NoteItem note) {
ViewSwitcher switcher = (ViewSwitcher) context.findViewById(R.id.noteItemVS);
View switchCheck = switcher.getCurrentView();
if (switchCheck instanceof EditText) {
EditText l = (EditText)switchCheck ;
String x = l.getText().toString();
Log.e("tree",x);
if (!x.isEmpty()) {
switcher.showPrevious();
TextView myTV = (TextView) switcher.findViewById(R.id.noteItemTextView);
myTV.setText(x);
}
}
; if (switchCheck instanceof TextView) {
TextView l = (TextView) switchCheck;
String x = l.getText().toString();
switcher.showNext();
EditText myEditText = (EditText) switcher.findViewById(R.id.noteItemEditText);
myEditText.setText(x);
}
}