求助...
具体就是计算两个数相乘...代码运行,虽然能得出结果,但是要先崩溃一次才能得出结果...这个...谁能帮我我看看呀~~~Activity03Activity.java
package chong.Activity03;
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;
/*
* 1、在activity03中声明四个控件
* 2、为其中的两个控件设置显示的值
* 3、创建一个易做图类,监听按钮按下的动作
* 4、将易做图类的对象绑定在按钮对象上
*/
public class Activity03Activity extends Activity {
/** Called when the activity is first created. */
private EditText factorOne;
private EditText factorTwo;
private TextView symbol;
private Button calculate;
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对象上
calculate.setOnClickListener(new CalculateListener());
}
//内部类可以使用外部类的成员变量和函数 “内部类”
class CalculateListener implements OnClickListener{
@Override
public void onClick(View v) {
/*
* 取得两个edittext的值
* 将这两个值存放到intent对象当中
* 使用这个intent对象来启动resultactivity
*/
String factorOneStr=factorOne.getText().toString();
String factorTwoStr=factorTwo.getText().toString();
Intent intent = new Intent();
intent.putExtra("one", factorOneStr);
intent.putExtra("two", factorTwoStr);
intent.setClass(Activity03Activity.this, ResultActivity.class);
Activity03Activity.this.startActivity(intent);
}
}
}
ResultActivity.java
package chong.Activity03;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
/*
* 1、接受从activity03中所传递的值
* 2、计算两个值的积
* 3、将计算的结果显示在activity上
*/
public class ResultActivity extends Activity {
private TextView resultView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
resultView = (TextView)findViewById(R.id.result);
Intent intent = getIntent();
String factorOneStr = intent.getStringExtra("one");
String factorTwoStr = intent.getStringExtra("two");
int factorOneInt = Integer.parseInt(factorOneStr);
int factorTwoInt = Integer.parseInt(factorTwoStr);
int result ;
result = factorOneInt * factorTwoInt;
resultView.setText(result+"");
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/factorOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/symbol"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText
android:id="@+id/factorTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/calculate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
result.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Activity03Activity!</string>
<string name="app_name">Activity03</string>
<string name="resultLable">result</string>
<string name="symbol">乘以</string>
<string name="calculate">计算</string>
</resources> --------------------编程问答-------------------- 崩溃是logcat输出日志是什么呢
补充:移动开发 , Android