我有一个简单的测验应用程序。它有六个片段和一个得分页面,其中包含正确和错误答案的数量。在每个片段中都有一个问题,答案的单选按钮和“提交”。 (btn1)按钮。在这个按钮中检查答案,它一直工作到这里但是当我在onClick方法中编写代码来移动另一个页面时,它出错了。我的错是什么?
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);
}
});
}
}
在manifest.xml中可能是个错误吗?
的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>
答案 0 :(得分:0)
您只需要用于打开新活动的活动上下文。
Intent q1 = new Intent(getActivity(), Question2.class);
startActivity(q1);
答案 1 :(得分:0)
您需要在'C:\Program Files\Docker\Docker\resources\MobyLinux.ps1' -Destroy
$service = Get-WmiObject -Class Win32_Service -Filter "Name='com.docker.service'"
$service.StopService()
$service.Delete()
Start-Sleep -s 5
Remove-Item -Recurse -Force "~/AppData/Local/Docker"
Remove-Item -Recurse -Force "~/AppData/Roaming/Docker"
takeown.exe /F "C:\ProgramData\Docker" /R /A /D Y
icacls "C:\ProgramData\Docker" /T /C /grant Administrators:F
Remove-Item -Recurse -Force "C:\ProgramData\Docker"
Remove-Item -Recurse -Force "C:\Program Files\Docker"
Remove-Item -Recurse -Force "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Docker"
Remove-Item -Force "C:\Users\Public\Desktop\Docker for Windows.lnk"
Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $.PSPath} | Where-Object { $.DisplayName -eq "Docker" } | Remove-Item -Recurse -Force
Get-ChildItem hklm:\software\classes\installer\products | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object { $_.ProductName -eq "Docker" } | Remove-Item -Recurse -Force
Get-Item 'HKLM:\software\Docker Inc.' | Remove-Item -Recurse -Force
Get-ItemProperty -path HKCU:\software\microsoft\windows\currentversion\Run -name "Docker for Windows" | Remove-Item -Recurse -Force
喜欢这个
onCreateView(){
我还建议你在onCreateView()
中引用单选按钮btn=(Button)v.findViewById(R.id.b tn1);
答案 2 :(得分:0)
删除getview()
btn=(Button) findViewById(R.id.btn1);
和
Intent intent = new Intent(Question1.this, Question2.class);
startActivity(intent);