2 つの Java クラスと 2 つの xml ページを作成しました。あるクラスのボタンをクリックすると、別のクラスを開こうとしています。開くと memo.xml ページが空白になります。次のコードを参照してください。私を助けてください
私の login.java ページ:
package quesansw.the1;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends Activity{
SQLiteDatabase db;
int z,i=0;
String[] arr = new String[3];
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = openOrCreateDatabase("mydatabase.db",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
final Dialog d1 = new Dialog(this);
Window window = d1.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
d1.setTitle("Login");
d1.setContentView(R.layout.login);
d1.show();
Button registerques1 = (Button) d1.findViewById(R.id.registerques1);
EditText ques = (EditText) d1.findViewById(R.id.question);
Cursor cur= db.rawQuery("select * from questions1",null);
cur.moveToNext();
System.out.println(cur.getString(0));
System.out.println(cur.getString(1));
ques.append(cur.getString(0));
Cursor c = db.rawQuery("SELECT * from questions1", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String firstName = c.getString(c.getColumnIndex("question"));
String Name = c.getString(c.getColumnIndex("answer"));
arr[i]=firstName;
i++;
}while (c.moveToNext());
}
}
for(z=0;z<2;z++)
{
registerques1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
if(z == 2)
{
Cursor cur= db.rawQuery("select * from questions1",null);
cur.moveToNext();
EditText ques = (EditText) d1.findViewById(R.id.question);
EditText ans = (EditText) d1.findViewById(R.id.answer);
Editable newTxt=(Editable)ans.getText();
String str = newTxt.toString();
int l=str.length();
int l1=cur.getString(1).length();
int l2=l-l1;
ques.setText(arr[0]);
ans.setText("");
if(l2 == 0)
{
z=5;
}
}
if(z == 5)
{
EditText ques = (EditText) d1.findViewById(R.id.question);
ques.setText(arr[1]);
Cursor cur= db.rawQuery("select * from questions1 where question='"+arr[1]+"' ",null);
cur.moveToNext();
//ques.setText();
EditText ans = (EditText) d1.findViewById(R.id.answer);
System.out.println("------"+ans.getText());
Editable newTxt=(Editable)ans.getText();
String str = newTxt.toString();
int l=str.length();
int l1=cur.getString(1).length();
int l2=l-l1;
ques.setText(arr[1]);
ans.setText("");
/*ques.setText(arr[2]);
ans.setText("");*/
if(l2 == 0)
{
/*Intent intent = new Intent(getBaseContext(), Memo.class);
startActivity(intent);*/
z=6;
}
}
if(z == 6)
{
EditText ques = (EditText) d1.findViewById(R.id.question);
ques.setText(arr[2]);
Cursor cur= db.rawQuery("select * from questions1 where question='"+arr[2]+"' ",null);
cur.moveToNext();
EditText ans = (EditText) d1.findViewById(R.id.answer);
System.out.println("------"+ans.getText());
Editable newTxt=(Editable)ans.getText();
String str = newTxt.toString();
int l=str.length();
int l1=cur.getString(1).length();
//System.out.println(l+l1);
int l2=l-l1;
ques.setText(arr[2]);
ans.setText("");
if(l2 == 0)
{
System.out.println("memo-----");
Intent intent = new Intent(getBaseContext(), Memo.class);
startActivity(intent);
}
}
}
});
}
}
}
login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<TextView android:text="Question1" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/question" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<EditText android:id="@+id/answer" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<Button android:id="@+id/registerques1" android:layout_width="wrap_content" android:text="registerques" android:layout_height="wrap_content"></Button>
</LinearLayout>
メモ.java
package quesansw.the1;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class Memo extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Dialog d1 = new Dialog(this);
Window window = d1.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
d1.setTitle("Register Questions");
d1.setContentView(R.layout.memo);
Button view = (Button) d1.findViewById(R.id.view);
view.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
/*Intent intent = new Intent(getBaseContext(), View.class);
startActivity(intent);*/
}
});
}
}
memo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<TextView android:text="Titile" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/question" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<TextView android:text="Text" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:minLines="6" android:maxLines="10" android:id="@+id/answer" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<TableLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button android:id="@+id/add" android:layout_width="wrap_content" android:text="ADD" android:layout_height="wrap_content"></Button>
<Button android:id="@+id/view" android:layout_width="wrap_content" android:text="VIEW" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
</LinearLayout>