Ad
How To Create A Clickable Edittext?
I know a there is a lot of similar questions out there, but none of them work for me. I want to make a EditText
that acts like a Button
. I want it to be not editable (and no keyboard should popup). However, when I set an onClickListener()
, the EditText
doesn't react to my onClick()
event. How should I do this correctly?
In my xml I disabled the focusableInTouchMode
and I set the clickable
to be true. My resulting EditText
is not editable, but it doesn't response to my onClickListener()
.
My xml of the EditText
:
<EditText
android:id="@+id/taskviewer_date"
android:focusableInTouchMode="false"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="normal"
android:textColorHint="@color/colorShadow"
android:inputType="none"
android:hint="No Due Date"/>
My Code:
EditText text = (EditText) findViewById(R.id.taskviewer_date);
text.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("taskviewer", "OnClickListener called !");
}
}
);
Ad
Answer
Use onTouch events or put a clickable FrameLayout over your EditText to catch click events. Make FrameLayout's visibility Gone when you want your edittext to be editable
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad