フラグメントを使用する 2 つのクラスがあります。FirstFragment クラスと SignUp クラス。一度に 1 つのフラグメントを使用します。FirstFragment にはボタンがあり、ボタンをクリックすると次のフラグメントに移動する必要があります。しかし、ボタンをクリックするとエラーが発生しました。
FirstFragment クラスのコードは次のとおりです。
package com.example.bajraregistertesteclipse;
import java.util.zip.Inflater;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class FirstFragment extends Fragment {
LoginDataBaseAdapter loginDataBaseAdapter;
EditText loginTestUser,loginTestPassword,loginTestConfirmPassword;
String userName,password,confirmpassword;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.firstfragment, container, false);
Button btnSignup = (Button) view.findViewById(R.id.buttonCreateAccount);
btnSignup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SignUp signup=new SignUp();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.listFragment, signup);
ft.addToBackStack(null);
ft.commit();
}
});
return view;
}
}
activity_main xml のコードは次のとおりです。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment
android:id="@+id/listFragment"
android:layout_width="211dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
class="com.example.bajraregistertesteclipse.FirstFragment"
tools:layout="@layout/firstfragment"/>
前もって感謝します!!!
私の丸太猫
log cat
05-27 19:46:29.635: E/ActivityThread(768): at java.lang.Thread.run(Thread.java:856)
05-27 19:46:29.716: E/StrictMode(768): null
05-27 19:46:29.716: E/StrictMode(768): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cebd08 that was originally bound here
05-27 19:46:29.716: E/StrictMode(768): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
05-27 19:46:29.716: E/StrictMode(768): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
05-27 19:46:29.716: E/StrictMode(768): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
05-27 19:46:29.716: E/StrictMode(768): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
05-27 19:46:29.716: E/StrictMode(768): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-27 19:46:29.716: E/StrictMode(768): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-27 19:46:29.716: E/StrictMode(768): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-27 19:47:20.355: E/ActivityThread(768): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d18928 that was originally bound here
05-27 19:47:20.355: E/ActivityThread(768): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-27 19:47:20.355: E/ActivityThread(768): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
私の登録クラス
package com.example.bajraregistertesteclipse;
import java.util.zip.Inflater;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SignUp extends Fragment{
LoginDataBaseAdapter loginDataBaseAdapter;
EditText loginTestUser,loginTestPassword,loginTestConfirmPassword;
String userName,password,confirmpassword;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
final View view = inflater.inflate(R.layout.signup, container, false);
loginDataBaseAdapter= loginDataBaseAdapter.open();
final EditText loginTestUser = (EditText) view.findViewById(R.id.editTextUserName);
final EditText loginTestPassword = (EditText) view.findViewById(R.id.editTextPassword);
final EditText loginTestConfirmPassword = (EditText) view.findViewById(R.id.editTextConfirmPassword);
Button btnSignup = (Button) view.findViewById(R.id.buttonCreateAccount);
btnSignup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//loginTestUser = (EditText) view.findViewById(R.id.editTextUserName);
userName=loginTestUser.getText().toString();
// loginTestPassword = (EditText) view.findViewById(R.id.editTextPassword);
password=loginTestPassword.getText().toString();
// loginTestConfirmPassword = (EditText) view.findViewById(R.id.editTextConfirmPassword);
confirmpassword=loginTestConfirmPassword.getText().toString();
// String userName = loginTestUser.getText().toString();
// String password = loginTestPassword.getText().toString();
// String confirmpassword = loginTestConfirmPassword.getText().toString();
//check if any of the fields are vacant
if (userName.equals("") || password.equals("") || confirmpassword.equals("")) {
Toast.makeText(getActivity(), "Field Vaccant", Toast.LENGTH_LONG).show();
return;
}
// check if both password matches
if (!password.equals(confirmpassword)) {
Toast.makeText(getActivity(), "Password does not match", Toast.LENGTH_LONG).show();
return;
} else {
// Save the Data in Database
loginDataBaseAdapter.insertEntry(userName, password);
Toast.makeText(getActivity(), "Account Successfully Created ", Toast.LENGTH_LONG).show();
}
}
});
return view;
}
}