【发布时间】:2015-04-17 10:23:45
【问题描述】:
我解释我的问题。
我有一个视图,其中有两个按钮和两个editText。 如果我触摸 button1,我想显示 edidText1。 如果我触摸button2,我想显示edidText2。
在我的布局中,edidText1 的可见性可见,edidText2 的可见性消失了。
My_Layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_comments1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/form_comments"/>
<Button
android:id="@+id/btn_comments2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<EditText
android:id="@+id/et_comments1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:gravity="top" />
<EditText
android:id="@+id/et_comments2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:gravity="top" />
</LinearLayout>
在我的 onCreate 函数中
final EditText etComments1 = (EditText) alertDialogView.findViewById(R.id.et_comments);
etComments1.setText(comment1);
etComments1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Toast.makeText(context, "TODO_1", Toast.LENGTH_LONG).show();
}
});
final EditText etComments2 = (EditText) alertDialogView.findViewById(R.id.et_mes_corr);
etComments2.setText(comment2);
etComments2.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Toast.makeText(context, "TODO_2", Toast.LENGTH_LONG).show();
}
});
final Button btnComments1 = (Button) alertDialogView.findViewById(R.id.btn_comments1);
final Button btnComments2 = (Button) alertDialogView.findViewById(R.id.btn_comments2);
btnComments2.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
etComments1.setVisibility(View.INVISIBLE);
etComments2.setVisibility(View.VISIBLE);
}
});
btnComments1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
etComments1.setVisibility(View.VISIBLE);
etComments2.setVisibility(View.INVISIBLE);
}
});
当第一次点击我的 etComments1 时,TODO_1 被调用。 在我单击我的 btnComments2 以显示 etComments2 后,当我单击它时,不会调用 TODO_2。 在我点击我的 btnComments1 显示 etComments1 后,当我点击它时,TODO_1 没有被调用。
所以我在想,可以来view.Gone。所以我也在按钮的onClick中实现了这个事件,但问题还是一样。
有人可以帮助我吗?
【问题讨论】:
-
你怎么知道它没有被调用?这只是一个注释,所以没有代码可以在那里运行。您究竟希望发生什么?为什么要点击
EditText视图? -
我没有把应该调用的确切代码放在函数中。
-
尝试将
android:clickable="true"添加到您的EditTexts。你可能还需要android:editable="false" -
我尝试使用
android:clickable="true"但这会改变任何事情。加了android:editable="false",还是不行,但是好一点,要调用onclick,我需要点击两次。 -
已经有一段时间了,不太乐观,但你也可以试试
android:focusableInTouchMode="false"。你能解释一下你想要发生的事情吗?可能有更好的方法
标签: android view visibility