Ich habe etwa 50 Aktivitäten in meiner App und ich habe einen Algorithmus, der den Titel von etwa 10 dieser Aktivitäten in Form von Schaltflächen in einer Superaktivität anzeigt und legt einen onclicklistener zu jeder Schaltfläche, die enthält eine Absicht und ruft die spezifische Aktivität auf. Ich habe versucht, dies über eine Reihe von Absichten zu tun, aber ich habe keinen Erfolg. Irgendwelche Vorschläge, wie ich das ausführen kann?Arbeiten mit Array von Absichten android
package plkk.developers.com.livfit;
// this is my string which contains name of activities
final String ActivityIdMen[] = { "Deadlift", "Pushups", "Barbell_Bench", "Military_Press", "Barbell_Curl", "Close_Bench", "Seated_Cable", "Chinup", "Overhead_Press",
"Power_Clean", "Jumping_Rope", "Hiit", "Barbell_Bench", "Deadlift", "Lat_Pulldown", "Barbell_Curl", "Skull_Crusher", "Diamond_Dips", "Squats",
"Hill_Running", "Jumping_Rope", "Stationary_Bike", "Hiit", "Chinup", "Torso_Rotation", "Prone_Plank", "Medicine_Squat", "Front_Squat"
};
// this is a fragment of the algorithm where I need help
if(BMI<18.5){
for(i=0;i<=8;i++) {
Button btn = new Button(this);
LinearLayout.LayoutParams P = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
P.weight = 1;
btn.setLayoutParams(P);
btn.setText(ActivityTextMen[i]);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Class clas = null;
try{
clas = Class.forName("plkk.developers.com.livfit."+ActivityIdMen[i]);
}catch (ClassNotFoundException c){
c.printStackTrace();
}
if (clas!=null) {
Intent intent = new Intent(view.getContext(), clas);
startActivity(intent);
}
}
});
ll.addView(btn);
}
// the intent always directs me to the class at i=9 (in the above case. I tried solving it by using array of intents but couldn't do that properly.
Können Sie Code anzeigen? Was meinst du, du hast keinen Erfolg? Hat es deine App kaputt gemacht? – drum
Können Sie bitte noch einmal überprüfen, ich habe den Code hochgeladen. Nein, es hat meine App nicht kaputt gemacht. – Prajjwal