automatically update my activity to show which was written

前端 未结 1 672
旧时难觅i
旧时难觅i 2020-12-04 03:54

Like you can see here, the user must provide a sim card number and when this number is provided, i would like to fill the content automatically by myself adding the sim card

相关标签:
1条回答
  • 2020-12-04 04:31

    What you want is TextWatcher. Use onTextChanged() so that as the user types in the "Sim card" box, the "content" box is filling up. So attach the TextWatcher to your first EditText

    edit1.addTextChangedListener(new TempWatcher());
    

    and create an inner class for TextWatcher

    private class TempWatcher implements TextWatcher {
    
        @Override
        public void afterTextChanged(Editable s) {
        }
    
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) 
        {   
             if (s.length() > 0) 
             {
                 String sim = s.toString();
                 edit2.setText(sim);
             }
    
        }
    

    You will probably want to make your EditTexts member variables so declare them before onCreate() then initialize them as you are in onCreate(). This should get you started. I wrote it quickly so you may need to tweak variable names, error checking if needed, and such. Let me know if that helps

    Edit

    public class RegulationTime extends Activity {
    
      EditText edit1, edit2;   // declare them here so they are member variables
    
     @Override
       protected void onCreate(Bundle savedInstanceState) {
    
    
       super.onCreate(savedInstanceState);
       setContentView(R.layout.regulation_time);
       // Show the Up button in the action bar.
       setupActionBar();
    
       //Récupérer le n° de la carte SIM saisi par l'utilisateur
       edit1 = (EditText) findViewById(R.id.regedit1);   // initialize here
       String simCard = edit1.getText().toString();
    
       //Récupérer le n° du destinataire & le saisir automatiquement dans l'EditText
       String recoverRN = MasterNumber.getDefaults("mehmet", RegulationTime.this);
       edit2 = (EditText) findViewById(R.id.regedit2);   // initialize here
       edit2.setText(recoverRN);
    
    0 讨论(0)
提交回复
热议问题