-2

I would like to have an EditText that is disabled for user input but the user can click on it to open dialog.

So I did the following:

        <EditText android:id="@+id/select" android:layout_width="match_parent"
            android:layout_height="wrap_content" android:hint="Click here"
            android:maxLines="1"
            android:editable="false" android:clickable="true"
            android:singleLine="true" android:layout_marginTop="16dp"
            android:onClick="openDialog"
            android:enabled="true" />

The onCreateView method is:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_custom, container);

    return view;
}

I'm using an EditText and not a TextView because I would like to show a hint the and line below the text.

It partially works, because when the edittext is not focused I have to click a second time on it for the dialog to open.

Is it possible to have it in such a way that the user needs to click only once on it to open the dialog?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • post your `openDialog` method – Jibran Khan Jun 10 '15 at 12:01
  • "I'm using an EditText and not a TextView because I would like to show a hint the and line below the text." You can easily underline the text in Textview, why taking so much pain? Follow: http://stackoverflow.com/questions/2394935/can-i-underline-text-in-an-android-layout – AnswerDroid Jun 10 '15 at 12:11
  • @JibranKhan I only have onCreateView. – Ivan-Mark Debono Jun 10 '15 at 12:12
  • so how you open the dialog after clicking twice ? "It partially works, because when the edittext is not focused I have to click a second time on it for the dialog to open." What does this mean if `openDialog` is not implemented – Jibran Khan Jun 10 '15 at 12:24
  • The way you are doing is not correct. you can do it easily with textview. But if you want to do it with EditText. Then after disabling the EditText just override the onTouch() method. And do the code whatever you want .. – Moinkhan Jun 10 '15 at 12:26

1 Answers1

0

There's actually a much better way. Use a TextView instead, for example:

        <TextView style="@android:style/Widget.EditText"
            android:id="@+id/TextView01"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </TextView>
Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263