this is my situation: I want to show a few fragments. In my case, I have a sqlite database with a some students, the fields are: _id, Name, Lastname, sex, photoSize, field1, field2, field3, field4. For example, if field1 == 1 i have to show the fragment 1, if field2 == 2 i have to show the fragment 2 and so. I don't know what i am doing wrong. Here is the code.
public class SectionsPagerAdapter extends FragmentPagerAdapter {
Bundle b = getIntent().getExtras();
int i = 2;
Cursor c;
Cursor c2;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
String id = b.getString("id");
c2 = dbm.buscarAlumno(id);
if (c.moveToFirst()) {
switch (position) {
case 0:
if (c2.getString(5).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 1:
if (c2.getString(6).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 2:
if (c2.getString(7).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 3:
if (c2.getString(8).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 4:
return PlaceholderFragment.newInstance(position);
}
}
return null;
}
@Override
public int getCount() {
// Show 1 total pages.
return 5;
}
@Override
public CharSequence getPageTitle(int position) {
String id = b.getString("id");
c = dbm.buscarAlumno(id);
if (c.moveToFirst()) {
switch (position) {
case 0:
if (c.getString(5).equals("1")){
return "PISTA";
}
case 1:
if (c.getString(6).equals("1")){
return "ESTABLO";
}else{break;}
case 2:
if (c.getString(7).equals("1")){
return "EMOCIONES";
}else{break;}
case 3:
if (c.getString(8).equals("1")){
return "NECESIDADES";
}else{break;}
case 4:
return b.getString("alumno");
}
}return null;
}
}
The dbm variable is declare in the container class, means DataBaseManager, and buscarAlumno(id) is the method that returns the student, and swear that this method works perfect. Here is the logcat:
12-30 07:43:14.419 3104-3104/? W/EGL_emulation: eglSurfaceAttrib not implemented
12-30 07:43:14.429 3104-3104/? D/OpenGLRenderer: Enabling debug mode 0
12-30 07:43:17.849 1340-1354/? W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException
at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
12-30 07:43:17.849 1253-1353/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 3076 uid 10057
If i don't use the database works perfectly.
Please help! Thanks folks!
Aucun commentaire:
Enregistrer un commentaire