Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editable textview on click

I have a screen with textviews now i want to make this editable on click of that

i tried one solution using edittext making it as transparent background but initially it will show cursor and the click is not recognizing properly,if i set focusbaleintouchmode to false in xml it is not getting focus.but some how the click is not working properly as expected.first is this correct approach?

expected result is textview should be there once user clicks on it it should be editable once user clicks outside it it should be not editable. any sample code will helps me a lot.sorry for my english

Thanks in advance

finally i got one solution using below code in xml edit text i gave foucasbletouchmode to false which makes click works properly after that with in onclick

        et.setFocusable(true);
        et.setEnabled(true);

        et.setFocusableInTouchMode(true);
        et.requestFocus();

to lose focus

        et.setFocusable(false);
        et.setClickable(true);
        et.clearFocus();
like image 830
Manju Avatar asked Nov 16 '12 06:11

Manju


1 Answers

You can use the below code :

private makeEditable(boolean isEditable,EditText et){
    if(isEditable){
        et.setBackgroundDrawable("Give the textbox background here");//You can store it in some variable and use it over here while making non editable.
        et.setFocusable(true);
        et.setEnabled(true);
        et.setClickable(true);
        et.setFocusableInTouchMode(true);
        et.setKeyListener("Set edit text key listener here"); //You can store it in some variable and use it over here while making non editable.
    }else{
        et.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        et.setFocusable(false);
        et.setClickable(false);
        et.setFocusableInTouchMode(false);
        et.setEnabled(false);
        et.setKeyListener(null);
    }
}
like image 92
Eldhose M Babu Avatar answered Nov 13 '22 17:11

Eldhose M Babu