Ich habe eine einfache Quiz-Anwendung. Es hat sechs Fragmente und eine Ergebnisseite, die die Anzahl der richtigen und falschen Antworten enthalten. In jedem Fragment gibt es eine Frage, einen Radio-Knopf für Antworten und eine Schaltfläche "Senden" (btn1). In dieser Taste ist die Antwort aktiviert, es funktioniert bis hierhin, aber wenn ich Code in die onClick-Methode schreibe, um eine andere Seite zu verschieben, ist etwas falsch gelaufen. Was wäre der Fehler?Wie wird die Seite auf eine andere Aktivität umgeleitet?
public class Question1 extends Fragment {
RadioButton q1a2;
Button btn1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_question1, null);
return v;
}
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
q1a2 = (RadioButton)getView().findViewById(R.id.q1a2);
btn1 =(Button)getView().findViewById(R.id.btn1);
final SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = app_preferences.edit();
if(q1a2.isChecked()){
editor.putInt("answer_value", 1);
}else{
editor.putInt("answer_value", 0);
}
editor.commit();
Intent q1 = new Intent(Question1.this.getActivity(), Question2.class);
startActivity(q1);
}
});
}
}
ein Fehler in manifest.xml sein könnte?
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pc.quizapplicationproject">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Register"></activity>
<activity android:name=".MainQuizActivity">
<activity android:name=".Question1"/>
<activity android:name=".Question2"/>
</activity>
<activity android:name="com.example.pc.quizapplicationproject.Score" />
</application>