This site requires JavaScript, please enable it in your browser!
Greenfoot back
BradH
BradH wrote ...

2013/2/3

Menu Problem for android app

BradH BradH

2013/2/3

#
Hi, I have this class called Menu (in eclipse) and its purpose is to set up a menu. When I click on one of the Strings (MainActivity, example1 etc.) it is to see if the thing clicked is a class (my MainActivity is a class) and if it is a class the class should run that class. My problem is that when I click my MainActivity on the menu nothing happens. I have looked at this and my manifest for hours but I still can not find a solution.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.bradhstudios.Brad;
 
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[] = {"MainActivity", "example1", "example2", "example3",
            "example4", "example5", "example6"};
 
     
     
     
     
     
    @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 select = classes[position];
        try{
        Class ourClass = Class.forName("com.bradhstudios.brad." + select);
        Intent ourIntent = new Intent(Menu.this, ourClass);
        startActivity(ourIntent);
    }catch(ClassNotFoundException e){
    e.printStackTrace();
  }
 }
}
BradH BradH

2013/2/3

#
here is my manifest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    package="com.bradhstudios.Brad"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        
        <activity
            android:name=".Splash"
            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=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.bradhstudios.brad.MENU" />
 
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
               android:name=".MainActivity"
               android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.bradhstudios.brad.MAINACTIVITY" />
 
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>
You need to login to post a reply.