Android简单按钮

时间:2013-11-18 09:38:29

标签: android button view manifest

What did i wrong ?

我认为我在意图行动和startActivity上错了。我该怎样才能正常工作?

主要活动:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button buttonPainting = (Button)findViewById(R.id.buttonPainting);
    buttonPainting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            startActivity(new Intent("com.example.menupainting.paintingbutton"));      here i put  paintingbutton.java ?
        }
    });

主要活动xml:

    <Button
        android:id="@+id/buttonPainting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight ="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="24dp"
        android:text="Paint" />

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.menupainting"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.menupainting.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.menupainting.paintingbutton"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.PAINTINGBUTTON" />   Here on intent action what should i put
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

5 个答案:

答案 0 :(得分:1)

更改此行:

startActivity(new Intent("com.example.menupainting.paintingbutton")); here i put paintingbutton.java ?

到此:

startActivity(new Intent(this, paintingbutton.class));

答案 1 :(得分:1)

试试这个:

Intent intent = new Intent(MainActivity.this, paintingbutton.class);
startActivity(intent);

而不是:

startActivity(new Intent("com.example.menupainting.paintingbutton"));

答案 2 :(得分:0)

如果你想用Intent开始另一个活动,你应该按如下方式启动它:

Intent intent = new Intent(CurrentActivity.this, GotoActivity.class);

startActivity(intent);

答案 3 :(得分:0)

另一项活动就是这样开始的:

> buttonPainting.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(FirstAct.this,SecondAct.class);
        startActivity(intent);
    }
});

答案 4 :(得分:0)

只是做:

buttonPainting.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        startActivity(new Intent(MainActivity.this, paintingbutton.class));
    }
});