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 EditText
s 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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…