</pre><p></p><p><span style="font-size:12px"><strong>Textview</strong></span></p><p><span style="font-size:12px"><strong>文本</strong></span></p><p> </p><p><span style="font-size:12px"><strong>Edittext</strong></span></p><p><span style="font-size:12px"><strong>可编辑文本框</strong></span></p><p> </p><pre name="code" class="java">super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1=(EditText)findViewById(R.id.editText1);
editText1=(EditText)findViewById(R.id.editText2);
textView1=(TextView)findViewById(R.id.textView1);
Buttoncheng=(Button)findViewById(R.id.Buttoncheng);
//设置显示值
textView1.setText(R.string.textView1);
取得值并传递到intent
String editText1Str=editText1.getText().toString();
String editText2Str=editText1.getText().toString();
//将两个值存放到intent中
Intent intent=new Intent();
intent.putExtra("one",editText1Str);
intent.putExtra("two",editText2Str);
Button
按钮
Buttoncheng=(Button)findViewById(R.id.Buttoncheng);
//设置显示值
textView1.setText(R.string.textView1);
Buttoncheng.setText(R.string.Buttoncheng);
//绑定监听器到按钮对象上
Buttoncheng.setOnClickListener(new ButtonListener());
Menu
菜单
//不需要配置;当客户点击menu按钮时,调用该方法;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
menu.add(0,1,1,R.string.exit);
menu.add(0,2,2,R.string.about);
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
// int id = item.getItemId();
if (item.getItemId() == 1) {
finish();
}
return super.onOptionsItemSelected(item);
}
出现的问题及错误:
1,手动添加控件,手写布局文件,不能偷懒拖拽;
2,布局时使用相对布局;
3,添加menu时不需要配置布局文件;