0

嗨,我为我的 android 应用程序制作了一个列表菜单,并制作了菜单链接到的其他活动,但是当我运行它并单击列表项时,它不会将我链接到其他活动

代码在这里

menu.java(更新)

                            package com.example.taekwondobuddy.util;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class Menu extends ListActivity {

String classes[] = {"Tool","Techniques"} ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String cheese = classes[position];
    try{
    Class ourclass = Class.forName("com.example.taekwondobuddy" + cheese);
    Intent ourIntent = new Intent(Menu.this, ourclass);
    startActivity(ourIntent);
    } catch(ClassNotFoundException e){
        e.printStackTrace();

    }
}

工具.java

                 package com.example.taekwondobuddy.util;

                import android.app.ListActivity;
                import android.content.Intent;
               import android.os.Bundle;
               import android.view.View;
                import android.widget.ArrayAdapter;
           import android.widget.ListView;

     public class Tools extends ListActivity{

String classes[] = {"Counter","Accelermeter","Timer"} ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Tools.this, android.R.layout.simple_list_item_1, classes));
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String cheese = classes[position];
    try{
    Class ourclass = Class.forName("com.example.taekwondobuddy" + cheese);
    Intent ourIntent = new Intent(Tools.this, ourclass);
    startActivity(ourIntent);
    } catch(ClassNotFoundException e){
        e.printStackTrace();

    }
}

       }    

Technqiues.java

                package com.example.taekwondobuddy.util;

            import android.app.ListActivity;
            import android.content.Intent;
           import android.os.Bundle;
          import android.view.View;
       import android.widget.ArrayAdapter;
            import android.widget.ListView;

         public class Technqiues extends ListActivity {

String classes[] = {"Kicks","Sparring",} ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Technqiues.this, android.R.layout.simple_list_item_1, classes));
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String cheese = classes[position];
    try{
    Class ourclass = Class.forName("com.example.taekwondobuddy" + cheese);
    Intent ourIntent = new Intent(Technqiues.this, ourclass);
    startActivity(ourIntent);
    } catch(ClassNotFoundException e){
        e.printStackTrace();

    }
}

    }

清单

           <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.taekwondobuddy.util"
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.taekwondobuddy.util.Menu"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.taekwondobuddy.util.Tools"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.Tools" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.taekwondobuddy.util.Techniques"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.Techniques" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>


</manifest>

有什么想法有什么问题吗?

4

2 回答 2

1

利用

Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);

用于获取具有完整包名的类名,因为目前您失踪了.util,并确保您已添加所有活动AndroidManifest.xml

在类数组"Tkd Buddy"中,类名无效,因此请使用正确的类命名约定

于 2013-10-17T02:13:41.337 回答
0


内部intent-filter标签
action android:name="android.intent.action.Tools
/intent-filter
更改为
android:name="com.example.taekwondobuddy.util.Tools";

于 2013-10-17T02:24:21.043 回答