Android Activity 中常见的控件
2010-09-10 01:12:00 来源:WEB开发网61. }
62.
63. }
64. }
package kaier.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class Deom extends Activity { /** Called when the activity is first created. */ private Button button; private EditText editOne; private EditText editTwo; private TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //获取各个组件,并给其赋值 button=(Button)findViewById(R.id.button); editOne=(EditText)findViewById(R.id.strOne); editTwo=(EditText)findViewById(R.id.strTwo); textView=(TextView)findViewById(R.id.strCheng); button.setText(R.string.button); textView.setText(R.string.strCheng); button.setOnClickListener(new BclickListener()); } //菜单选项的添加 @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(1, 1, 1, R.string.exit); menu.add(1,2,2,R.string.about); return super.onCreateOptionsMenu(menu); } //对菜单选项进行控制 @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub if (item.getItemId()==1){ finish(); } return super.onOptionsItemSelected(item); } class BclickListener implements OnClickListener{ @Override public void onClick(View v) { Intent intent =new Intent(); intent.putExtra("one",editOne.getText().toString()); intent.putExtra("two", editTwo.getText().toString()); intent.setClass(Deom.this, Result.class); Deom.this.startActivity(intent); } } }
Result.java
1. package kaier.test;
2.
3. import android.app.Activity;
4. import android.content.Intent;
5. import android.os.Bundle;
更多精彩
赞助商链接