I’m trying to make my first list adapter with android, and it comes up with the list, but when I click the items, nothing happens. My only guess is the comment I have after the line that defines Class cvar.
package scouting.form;
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[] = {"SCOUTING","LOGIN","MAIN"};
@Override
protected void onCreate(Bundle savedInstanceState)
{
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)
{
super.onListItemClick(l, v, position, id);
String cheese= "com.cody.graham."+classes[position];
try{
Class cvar=Class.forName(cheese); //Eclipse has a warning on this line "Class is a raw type. References to generic type Class<T> should be parameterized". I don't really know what that means.
Intent intention=new Intent(Menu.this,cvar);
startActivity(intention);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
Edit:
Part of the AndroidManifest:
<activity android:name=".splash_screen" android:label="@string/title_activity_splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Login" android:label="@string/title_activity_login" android:exported="false">
<intent-filter>
<action android:name="com.cody.graham.LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Scouting" android:label="@string/title_activity_scouting" android:exported="false">
<intent-filter>
<action android:name="com.cody.graham.SCOUTING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Firstly, remove the
<intent-filter>sections from your manifest for both.Scoutingand.Login(leave the one for.splash_screen). Unless you need any of yourActivityclasses to be started from 3rd-party (external) apps, it is not necessary to declare action-based<intent-filter>sections – it’s also not good practice.Secondly, do as wtsang02 suggests and change the classes string array to…
Also, assuming the other
Activityclasses (such as Scouting etc) are in the same package asMenu, change this line…to be…
…and to get rid of the eclipse warning, this line…
…to…