您的位置:首页 > 编程语言

(碎片代码)Button事件添加监听器

2017-10-14 10:37 169 查看
安卓 button事件添加监听器

Button button=(Button)findViewById(R.id.button1);

 button.setOnClickListener(new OnClickListener(){

        public void onClick(View view){

        // Intent intent = new Intent(IntentDemoActivity.this, NewActivity.class);

          //      startActivity(intent);

        Intent intent= new Intent(IntentDemoActivity.this,NewActivity.class);

        startActivity(intent);

        }

        });

xml文件格式

  <Button

        android:id="@+id/button1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/textView1"

        android:layout_below="@+id/textView1"

        android:text="Button" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: