Capture EditText Lost Focus

I am a long-time, self-taught, amateur VB programmer who is now trying to teach himself Java and Android at the same time. I am saying this so that you know that I am not very good at talking about jargon, and very new to these two classes.

I developed an Android form that has a series of EditText blocks, the contents of each of which I want to save in an array after the user has filled it. I figured out how to do this if the user clicks the Enter key button. However, people do not actually do this: they click on the field, type and then click on the next element.

I VB, I could write code for the lostfocus event. But I can not find a similar method in Java.

Finally, the question is: is there a capture method when EditText has lost focus, so I can save typed data in this type without relying on the Enter key?

public boolean onKey(View v, int keyCode, KeyEvent event) { 
    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)){ 
        Editable wasted=edittext_asset.getText(); 
        vehdata[vehNo][Integer.parseInt((String) edittext_asset.getTag())]=wasted.toString(); 
        return true; 
    } 
    return false; 
} 

Please remember that I am so new to this that I am often still not sure where to put code snippets to make them work (new file? Oncreate method? Who knows). Any guidance you can give me will be gratefully and eternally appreciated.

+3
source share
2 answers

I just did something like this. I processed it by creating a for-loop that just got the contents of each edittext by id and added it to the array. I did this in the onclick method, since I did all this after the user clicked a button.

String ohhai;
String duh = et.getText().toString();
int number = Integer.parseInt(duh);
List<String> myCollection=new ArrayList<String>();
EditText stuff;
int editt;
String loggy;
for(int z = 0; z < number; z++){
    stuff = (EditText)findViewById(z);
    editt = stuff.getId();
    loggy = Integer.toString(editt);
    Log.e("How Many", loggy);
    ohhai = stuff.getText().toString();
    myCollection.add(ohhai);
}

String [] arr = myCollection.toArray(new String[myCollection.size()]);
String separator = "0";
StringBuffer result = new StringBuffer();
if (arr.length > 0) 
   result.append(arr[0]);
for (int h=1; h < arr.length; h++) {
    result.append(separator);
    result.append(arr[h]);
}
+1
source

Release in parts:

  • " lostfocus, Java".: OnFocusChangeListener API
  • " , EditText ": , abstract void onFocusChange(View v, boolean hasFocus)
  • ", , ": - : ( , / ), .

:

, , , , : : . java Android, , , . java android? API, . java- , Android , .

, - . EditText IME, View , View (, EditText, , Button). , "" .

, Android , . , - (., , Android Save Instance)

/ ( TextWatcher, ). , . - .

!

+6

All Articles