2013-05-15 41 views
0

就像你可以在这里看到的,用户必须提供一个SIM卡号码,当提供这个号码时,我想填写内容自动添加SIM卡号码是提供。 我认为我必须自动更新(Autoupdate?)活动或类似的东西。如果任何人都可以通过编辑我所做的或者通过提供示例来帮助我,这将非常有帮助! 非常感谢您自动更新我的活动,以显示哪些被写

我的应用程序的图像是在这里:http://imageshack.us/a/img199/1561/12216127.png

我的代码是在这里:

public class RegulationTime extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     EditText edit2; 

     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 
     EditText edit1 = (EditText) findViewById(R.id.regedit1); 
     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); 
     edit2.setText(recoverRN); 

     //On rentre automatiquement le texte "#152#SIMCardNumber#" à la place de l'utilisateur 
     EditText edit3 = (EditText) findViewById(R.id.regedit3); 
     String concatenation; 
     if(simCard.length()>0) 
     { 
      concatenation = "#152#" + simCard + "#"; 
      edit3.setText(concatenation); 
     } 
    } 

} 
+0

什么是您所遇到的问题?有错误吗? logcat的? – codeMagic

+0

@codeMagic我没有任何错误。我必须自动更新我的应用程序,但我不知道如何!就像你在我的活动中看到的一样,我什么也没做,因为我不知道我该怎么做这件事! – d3vpasha

+0

请更清楚地解释你想要发生的事情吗? – codeMagic

回答

2

你需要的是TextWatcher。使用onTextChanged(),以便当用户键入“SIM卡”框时,“内容”框将填满。所以附加TextWatcher你的第一个EditText

edit1.addTextChangedListener(new TempWatcher()); 

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); 
     } 

    } 

创建一个内部类,你可能想使你的EditText小号成员变量onCreate()之前如此宣布他们然后将它们初始化为你在onCreate()。这应该让你开始。我写得很快,所以你可能需要调整变量名称,如果需要错误检查,等等。让我知道这是否有助于

编辑

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

感谢您的回答,但是您可以编辑我的代码吗?或者给我写一些示例示例,因为我是一个Android开发新手 – d3vpasha

+0

我正在做一个小例子。有你如何设置它的基础知识 – codeMagic

+0

我编辑了我的答案。给那一枪。 – codeMagic

相关问题