-1

我刚刚开始一个新的应用程序,我添加了一个按钮,过去我没有遇到任何问题,但由于某种原因它现在不起作用。我只是想教那个按钮到另一个页面。你认为问题是什么?(忽略我还没有设置的微调器)

短信项目活动

public class TextingprojectActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

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

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

                startActivity(new Intent("practice.practice.TUTORIALONE "));
            }
        });
    }
}

教程1 Java

public class TutorialOne extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tutorial1);
    }

}

主要 XML

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:entries="@array/place_arrays"
        android:prompt="@string/Place"/>
    <Spinner 
        android:id="@+id/spinner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         />
    <Button 
        android:id="@+id/tutorial1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/save"
        />


</LinearLayout>

教程1 XML

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


</LinearLayout>

安卓清单

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

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TextingprojectActivity"
            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=".TutorialOne"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="practice.practice.TUTORIALONE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            </activity>
    </application>

</manifest>
4

3 回答 3

1

将您的意图调用更改为

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

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

            Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class);
            startActivity(n);
        }
    });
于 2013-01-21T03:36:26.800 回答
1

改变你的意图呼叫

Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class);
        startActivity(n);

还要intent-filter从清单中删除其余活动的声明。

 <intent-filter>
            <action android:name="practice.practice.TUTORIALONE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

改成喜欢...

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TextingprojectActivity"
        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=".TutorialOne"
        android:label="@string/app_name">

        </activity>
</application>
于 2013-01-21T03:49:27.240 回答
0

如果只需要重定向到第二个活动将您的代码更改为

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

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

        startActivity(new Intent(TextingprojectActivity.this,TutorialOne.class););
    }
});

并从您的清单 XML 中删除此块

       <intent-filter>
            <action android:name="practice.practice.TUTORIALONE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

这是什么practice.practice.TUTORIALONE???

于 2013-01-21T03:54:25.150 回答