Question

I have EditText with InputType of password and one ImageView like a button. So I want when user hold his finger on that image, InputType of EditText to become normal text, and when user remove finger, InputType again to be password. So how can I do this?

Was it helpful?

Solution

ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
imageView.setOnTouchListener(new View.OnTouchListener {
   public onTouch(View v, MotionEvent event){
    if (event.getAction() == MotionEvent.ACTION_DOWN)
    {
       //set edittext to normal
    }
    else if (event.getAction() == MotionEvent.ACTION_UP
    {
     // set edittext to password
    }
    return true;                         
   }
});

The above code should work, it might need a little tweaking - I can't test it at the moment. Should give you a good idea on how to handle it.

OTHER TIPS

You can do a setOnTouchListener on the Image and inside you can call the setInputType of the EditText. Just report to this link to see wich setInputType parameter suits you the most.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top