Activity第三节——04

</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时不需要配置布局文件;



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值