私はアンドロイド用のアプリを開発しており、それはクイズです。ページには 2 つのボタンがあります。1つは機能し、1つは機能しません。エミュレーターを開いてボタンを押すと、アプリが閉じて次のメッセージが表示されます。マニフェストと 3 つのアクティビティは次のとおりです。 2 つのボタンを含む Java ファイルは次のとおりです。
package com.saifandvarun.quizofidiocy;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle iLikeTennis) {
super.onCreate(iLikeTennis);
setContentView(R.layout.activity_main);
Button failstart = (Button) findViewById(R.id.loser);
failstart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.saifandvarun.quizofidiocy.FAILSCREEN"));
}
});
Button truestart = (Button) findViewById(R.id.the_quiz);
truestart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.saifandvarun.quizofidiocy.FIRSTQUESTION"));
}
});
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
一致する xml ファイルは次のとおりです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home_back" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:text="Welcome To The Quiz Of Idiocy."
android:textColor="#DF013A"
android:textSize="21dp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="34dp"
android:text="The rules are simple, get the question right, you move on, get it wrong, you're an idiot. (Oh yeah, and you lose)"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="@+id/the_quiz"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="102dp"
android:text="Just A Pointless Button..."
android:textSize="25dp"
android:textStyle="bold" />
<Button
android:id="@+id/loser"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="START!!"
android:textColor="#00FF00"
android:textSize="34dp"
android:textStyle="bold|italic" />
</RelativeLayout>
作業ボタンが移動する Java ファイルは次のとおりです。
package com.saifandvarun.quizofidiocy;
import android.app.Activity;
import android.os.Bundle;
public class Firstquestion extends Activity {
@Override
protected void onCreate(Bundle iLikeCricket) {
// TODO Auto-generated method stub
super.onCreate(iLikeCricket);
setContentView(R.layout.firstquestion);
}
}
これに一致するxmlレイアウトファイルは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
そして、ここにJavaの非動作ボタンがナビゲートするファイルがあります:
package com.saifandvarun.quizofidiocy;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Failscreen extends Activity {
MediaPlayer whawHawha;
@Override
protected void onCreate(Bundle iLikeTabletennis) {
// TODO Auto-generated method stub
super.onCreate(iLikeTabletennis);
setContentView(R.layout.failscreen);
MediaPlayer.create(Failscreen.this, R.raw.lose_sound);
whawHawha.start();
Button retry = (Button) findViewById(R.id.tryagain);
retry.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.MAIN"));
}
});
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
whawHawha.release();
}
}
そしてそのためのxmlファイル:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="LOSER!!! You lost, Idiot!"
android:textColor="#ff0000"
android:textSize="70dp"
android:textStyle="bold" >
</TextView>
<Button
android:id="@+id/tryagain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="22dp"
android:text="Try Again???"
android:textColor="#ffffff"
android:textStyle="bold|italic" >
</Button>
</RelativeLayout>
最後に、メインフェストは次のとおりです。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.saifandvarun.quizofidiocy"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
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=".Failscreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.saifandvarun.quizofidiocy.FAILSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Firstquestion"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.saifandvarun.quizofidiocy.FIRSTQUESTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
何が欠けているのかわからない。私を助けてください。