Reputation: 1217
I have three Edittext fields ed1,ed2,ed3. When user clicked the ed2 /ed3 I have opened the dialog and get the input from that dialog.For the first click cursor comes to the edittext box and for the next click only I can open the dialog to get the input. I need to show the dialog for the first click.
Upvotes: 3
Views: 10575
Reputation: 3966
To keep the EditText
typable you can do a little trick.
If it is only needed to open the Dialog
in first time and then use the EditText
normally you can do this:
public class EditTextActivity extends Activity {
EditText et1;
int clickCount = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et1 = (EditText) findViewById(R.id.main_et1);
et1.setFocusableInTouchMode(false);
setOnClickListeners();
private void setOnClickListeners(){
location.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (clickCount == 0){
OpenDialog(); //Call the function to open the dialog created by you
et1.setFocusableInTouchMode(true);
}
clickCount = 1;
}
});
}
Upvotes: 0
Reputation: 30168
That's the way the EditText behaves. They have to be focused first to trigger the onClick
event.
Edit: Like Barak points out, you can disable the "focusability" and you can make it open in one click. The drawback is that you won't be able to type on the EditText (which might be fine for your use case).
Upvotes: 1
Reputation: 16393
Set the EditText to unFocusable. That way the first touch registers as a click.
In your XML for the EditText(s) in question add:
android:focusableInTouchMode="false"
Upvotes: 20
Reputation: 13501
Why don't you use a Button instead.. but set its background as default EditText..
Upvotes: 2