• eclipse android 简单计算器入门 相关问题。
  • 其它

一个小型加法计算器,在输入框里输入数据,键入button后进入下一个activity显示了计算结果,这时候按下返回键,输入过的数据还会输入框在里面。请问,如何在按返回的同时,清空原有文本框EditView中输入过的内容,让我在下一次输入的时候,输入框里是空白?

此段为第一个页面

package dhu.qq.com;

import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ZuoyeActivity extends Activity {
   /** Called when the activity is first created. */
   private EditText et1;
   private EditText et2;
   private Button bt1;
   private Float f1, f2;

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       et1 = (EditText) findViewById(R.id.et1);
       et2 = (EditText) findViewById(R.id.et2);
       bt1 = (Button) findViewById(R.id.bt1);

       bt1.setOnClickListener(new OnClickListener() {

           @Override
           public void onClick(View v) {
               // TODO Auto-generated method stub
               f1 = Float.parseFloat(et1.getText().toString());
               f2 = Float.parseFloat(et2.getText().toString());


               Bundle bd1 = new Bundle();
               bd1.putFloat("iput1",f1);
               bd1.putFloat("iput2",f2);

               Intent itt1 = new Intent();
               itt1.putExtra("transfer_bundle", bd1);

               itt1.setClass(ZuoyeActivity.this, SecondyActivity.class);
               startActivity(itt1);

           }
       });
   }
}

此段为第二个页面

/**
*
*/
package dhu.qq.com;

import java.security.PublicKey;

import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

/**
* @author Administrator
*
*/
public class SecondyActivity extends Activity {

   /*
    * (non-Javadoc)
    *
    * @see android.app.Activity#onCreate(android.os.Bundle)
    */
   private TextView tv21;
   private Float f1, f2, f3;
   private String str;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       // TODO Auto-generated method stub
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main2);
       tv21 = (TextView) findViewById(R.id.tv21);

       Intent itt2 = new Intent();
       Bundle bd12 = new Bundle();

       itt2 = this.getIntent();
       bd12 = itt2.getBundleExtra("transfer_bundle");
       f1 = bd12.getFloat("iput1");
       f2 = bd12.getFloat("iput2");
       f3 = f1 + f2;

       str = String.valueOf(f3);
       tv21.setText(str);

   }
}


  • vicky    2020-03-25 11:01:27
  • 阅读 740    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信