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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top