求解 calculate.setOnClickListener(new CalculateListener());这句是什么意思。该怎么理解
packagemars.activity03;importandroid.app.Activity;importandroid.content.DialogInterfa...
package mars.activity03;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
//1、在Activity03中,要声明四个控件
//2、要为其中的两个控件设置显示的值
//3、创建一个监听器类,监听按钮按下的动作
//4、将监听器的对象,绑定在按钮对象上
public class Activity03 extends Activity {
/** Called when the activity is first created. */
private EditText factorOne;
private EditText factorTwo;
private TextView symbol;
private Button calculate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//根据控件的ID来取得代表控件的对象
factorOne = (EditText)findViewById(R.id.factorOne);
factorTwo = (EditText)findViewById(R.id.factorTwo);
symbol = (TextView)findViewById(R.id.symbol);
calculate = (Button)findViewById(R.id.calculate);
//为symbol和calculate设置显示的值
// symbol.setText("乘以");
// calculate.setText("计算");
symbol.setText(R.string.symbol);
calculate.setText(R.string.calculate);
//将监听器的对象绑定到按钮对象上面
calculate.setOnClickListener(new CalculateListener());
}
class CalculateListener implements OnClickListener{
@Override
public void onClick(DialogInterface dialog, int which) {
//1、取得两个EditText控件的值
String factorOnestr = factorOne.getText().toString();
String factorTwostr = factorTwo.getText().toString();
//2、将这两个值存放到Intent对象当中
Intent intent = new Intent();
intent.putExtra("one", factorOnestr);
intent.putExtra("two", factorTwostr);
intent.setClass(Activity03.this, ResultActivity.class);
//3、使用这个Intent对象来启动ResultActivity
Activity03.this.startActivity(intent);
}
}
} 展开
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
//1、在Activity03中,要声明四个控件
//2、要为其中的两个控件设置显示的值
//3、创建一个监听器类,监听按钮按下的动作
//4、将监听器的对象,绑定在按钮对象上
public class Activity03 extends Activity {
/** Called when the activity is first created. */
private EditText factorOne;
private EditText factorTwo;
private TextView symbol;
private Button calculate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//根据控件的ID来取得代表控件的对象
factorOne = (EditText)findViewById(R.id.factorOne);
factorTwo = (EditText)findViewById(R.id.factorTwo);
symbol = (TextView)findViewById(R.id.symbol);
calculate = (Button)findViewById(R.id.calculate);
//为symbol和calculate设置显示的值
// symbol.setText("乘以");
// calculate.setText("计算");
symbol.setText(R.string.symbol);
calculate.setText(R.string.calculate);
//将监听器的对象绑定到按钮对象上面
calculate.setOnClickListener(new CalculateListener());
}
class CalculateListener implements OnClickListener{
@Override
public void onClick(DialogInterface dialog, int which) {
//1、取得两个EditText控件的值
String factorOnestr = factorOne.getText().toString();
String factorTwostr = factorTwo.getText().toString();
//2、将这两个值存放到Intent对象当中
Intent intent = new Intent();
intent.putExtra("one", factorOnestr);
intent.putExtra("two", factorTwostr);
intent.setClass(Activity03.this, ResultActivity.class);
//3、使用这个Intent对象来启动ResultActivity
Activity03.this.startActivity(intent);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询