本文介绍了自动更新我的活动,以显示这是写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像你可以在这里看到,用户必须提供SIM卡号码,当提供这个数字,我想通过自己添加提供了所需的SIM卡号码自动填写的内容。我认为我必须更新自动(自动更新?)活动或类似的东西。如果有人能帮助我编辑我做了什么,或presenting样本的例子,这将是非常有益的!非常感谢你。

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

我的code是在这里:

 公共类RegulationTime延伸活动{

   @覆盖
   保护无效的onCreate(包savedInstanceState){

       的EditText EDIT2;

       super.onCreate(savedInstanceState);
       的setContentView(R.layout.regulation_time);
       //显示操作栏中的向上按钮。
       setupActionBar();

       //Récupérer了N°德拉点SIM塞斯相提并论L'utilisateur
       的EditText EDIT1 =(EditText上)findViewById(R.id.regedit1);
       字符串SIMCARD = edit1.getText()的toString()。

       //Récupérer了N°杜destinataire和放大器;乐saisir automatiquement丹斯欧莱雅的EditText
       字符串recoverRN = MasterNumber.getDefaults(穆罕默德,RegulationTime.this);
       EDIT2 =(EditText上)findViewById(R.id.regedit2);
       edit2.setText(recoverRN);

       //在rentre automatiquement乐texte#152#SIMCardNumber#点菜戴高乐utilisateur
       EditText上EDIT3 =(EditText上)findViewById(R.id.regedit3);
       字符串连接;
       如果(simCard.length()大于0)
       {
           级联=#152#+卡贴+#;
           edit3.setText(串联);
       }
   }

}
 

解决方案

你想要的是的。使用 onTextChanged(),以便为在SIM卡框中的用户类型,内容框填满。所以附加 TextWatcher 你的第一个的EditText

  edit1.addTextChangedListener(新TempWatcher());
 

和创建一个内部类 TextWatcher

 私有类TempWatcher实现TextWatcher {

    @覆盖
    公共无效afterTextChanged(编辑S){
    }

    @覆盖
    公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,之后INT){
    }

    @覆盖
    公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数)
    {
         如果(s.length()大于0)
         {
             字符串SIM = s.toString();
             edit2.setText(SIM);
         }

    }
 

您可能会希望在的onCreate你的的EditText 取值成员变量的宣布他们()然后对它们进行初始化因为你是在的onCreate()。这应该让你开始。我很快,所以你可能需要调整的变量名写的,如果需要,错误检查,和这样的。让我知道这是否有助于

修改

 公共类RegulationTime延伸活动{

  的EditText EDIT1,EDIT2; //声明他们,因此他们的成员变量

 @覆盖
   保护无效的onCreate(包savedInstanceState){


   super.onCreate(savedInstanceState);
   的setContentView(R.layout.regulation_time);
   //显示操作栏中的向上按钮。
   setupActionBar();

   //Récupérer了N°德拉点SIM塞斯相提并论L'utilisateur
   EDIT1 =(EditText上)findViewById(R.id.regedit1); //这里初始化
   字符串SIMCARD = edit1.getText()的toString()。

   //Récupérer了N°杜destinataire和放大器;乐saisir automatiquement丹斯欧莱雅的EditText
   字符串recoverRN = MasterNumber.getDefaults(穆罕默德,RegulationTime.this);
   EDIT2 =(EditText上)findViewById(R.id.regedit2); //这里初始化
   edit2.setText(recoverRN);
 

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 number which was provided.I think that i have to update automatically (Autoupdate?) the activity or something like that. If anyone can help me by editing what i have done or by presenting a sample example, it will be very helpfull!Thank you very much

The image of my application is here: http://imageshack.us/a/img199/1561/12216127.png

My code is here:

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

}
解决方案

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

这篇关于自动更新我的活动,以显示这是写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 18:26