Java – capture EditText lost focus

I am a long-term, self-taught amateur VB programmer. Now I am trying to teach myself Java and Android I say so, so you will know that I can't speak good language, and my pursuit of both is very new

I developed an Android form, which contains a series of edit text boxes. The contents of each box should be saved to the array after the user fills in If the user presses enter, I've figured out how to do this But people don't actually do this: they click on the box, type, and then click on the next element

I VB, I can write code for LostFocus event But I can't find a similar method in Java

Last question: is there a way to capture when EditText loses focus, so I can save this type of type data 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; 
}

Remember, I'm new to this, and I'm often unsure where to put code snippets to make them work (new file? Oncreate method? Who knows) You can give me any guidance, I will be very grateful and forever grateful

Solution

I just did something similar I handle it by creating a for loop, which simply gets the contents of each EditText by ID and adds its text to the array I did this in the onclick method because I did everything after the user clicked the 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]);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>