i'm using this code for checking my edittext focus or not :
gelar_pp=(EditText)polis.findViewById(R.id.gelar_pp);
gelar_pp.setOnFocusChangeListener(new OnFocusChangeListener() {
LinearLayout layout_nama_pp=(LinearLayout)findViewById(R.id.layout_nama_pp);
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1);
}else {
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1_klik);
}
} });
ibu_pp=(EditText)polis.findViewById(R.id.ibu_pp);
ibu_pp.setOnFocusChangeListener(new OnFocusChangeListener() {
LinearLayout layout_nama_pp=(LinearLayout)findViewById(R.id.layout_nama_pp);
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1);
}else {
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1_klik);
}
} });
edit_bukti_lain_pp=(EditText)polis.findViewById(R.id.edit_bukti_lain_pp);
edit_bukti_lain_pp.setOnFocusChangeListener(new OnFocusChangeListener() {
LinearLayout layout_nama_pp=(LinearLayout)findViewById(R.id.layout_nama_pp);
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1);
}else {
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1_klik);
}
} });
when i make simple my code, and change into :
gelar_pp.setOnFocusChangeListener(listener);
ibu_pp.setOnFocusChangeListener(listener);
edit_bukti_lain_pp.setOnFocusChangeListener(listener);
listener= new OnFocusChangeListener() {
LinearLayout layout_nama_pp=(LinearLayout)findViewById(R.id.layout_nama_pp);
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1);
}else {
layout_nama_pp.setBackgroundResource(R.drawable.border_corner_baris1_klik);
}
}
};
my code is not working, nothing change. is there any wrong with my code?
Try like this
edit_Text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
Toast.makeText(getApplicationContext(), "on focus", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(), "lost focus", Toast.LENGTH_LONG).show();
}
}
});
Add in XML
android:focusable="true"
android:focusableInTouchMode="true"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With