Android Activity 中常见的控件
2010-09-10 01:12:00 来源:WEB开发网6. import android.widget.TextView;
7.
8. public class Result extends Activity{
9. private TextView textView;
10. @Override
11. protected void onCreate(Bundle savedInstanceState) {
12. // TODO Auto-generated method stub
13. super.onCreate(savedInstanceState);
14. this.setContentView(R.layout.result);
15. Intent intent=getIntent();
16. textView=(TextView)findViewById(R.id.textView);
17. //获得传递过来的值
18. String strOne=intent.getStringExtra("one");
19. String strTwo=intent.getStringExtra("two");
20. int value=Integer.parseInt(strOne)*Integer.parseInt(strTwo);
21. textView.setText((value+""));
22.
23.
24. }
25.
26. }
package kaier.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class Result extends Activity{ private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.setContentView(R.layout.result); Intent intent=getIntent(); textView=(TextView)findViewById(R.id.textView); //获得传递过来的值 String strOne=intent.getStringExtra("one"); String strTwo=intent.getStringExtra("two"); int value=Integer.parseInt(strOne)*Integer.parseInt(strTwo); textView.setText((value+"")); } }
======================
main.xml
1. < ?xml version="1.0" encoding="utf-8"?>
2. < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:orientation="vertical"
4. android:layout_width="fill_parent"
5. android:layout_height="fill_parent"
6. >
7. < EditText
8. android:id="@+id/strOne"
更多精彩
赞助商链接