我可以根据片段名称检索 sqlite 数据吗?

can i retrieve sqlite data depending on fragments name?

嘿,我有 3 个片段(3 个选项卡),我希望第 1 列显示在文本视图选项卡 1 上,第 2 列显示在选项卡 2 上,然后第 3 列显示在我的数据库中的选项卡 3 上??? 当然,我的片段名称是选项卡 1 2 和 3.. 谢谢 ..!

public class DataBaseHelper 扩展 SQLiteOpenHelper {

public static final String DATABASE_NAME = "big.db";
public static final String TABLE_NAME = "images";
public static final String NAME = "name";
public static final String PLACE = "place";
**public static final Integer FLAG = 1;**


public DataBaseHelper(Context context) {

    super(context, DATABASE_NAME, null, 1);
    SQLiteDatabase db = this.getWritableDatabase();

}

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_IMAGES_TABLE = "CREATE TABLE images ( " +
            "ID  INTEGER PRIMARY KEY AUTOINCREMENT, " +
            **"flag INTEGER, " +**

            "name TEXT, " +
            "place TEXT )";

    db.execSQL(CREATE_IMAGES_TABLE);
}


@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
    db.execSQL("DROP TABLE IF EXISTS images");
    this.onCreate(db);
}

public void insertentry(String name, String place) {

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(NAME, name);
    contentValues.put(PLACE, place);
    **contentValues.put(flag,1);**

    db.insert(TABLE_NAME, null, contentValues);
    db.close();
}

public void insertentry(String name, String place,Integer flag) {

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(NAME, name);
    **contentValues.put(FLAG,flag)**
    contentValues.put(PLACE, place);
    **contentValues.put(flag,2)**

    db.insert(TABLE_NAME, null, contentValues);
    db.close();

}
public DbResponse getDataforTab1() {
    DbResponse obj = new DbResponse();
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + "where"+FLAG+**"=1 , null);**
    if (cursor.getCount() > 0) {
        cursor.moveToNext();
        obj.name = cursor.getString(cursor.getColumnIndex(NAME));
        obj.place = cursor.getString(cursor.getColumnIndex(PLACE));

    }

    cursor.close();
    return obj;
}

}

这是我的片段class每个片段都有相同的代码:

public class Tab1 extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,     Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab1, container, false);

ImageView imageView = (ImageView) v.findViewById(R.id.img1);
String photoPath = Environment.getExternalStorageDirectory() +   "/Download/image1.jpg";
Bitmap bitmap1 = BitmapFactory.decodeFile(photoPath);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
final Bitmap b = BitmapFactory.decodeFile(photoPath, options);

        DataBaseHelper db = new DataBaseHelper(getActivity());
        DbResponse response = db.getData();
        TextView textView = (TextView)v.findViewById(R.id.txt3);
        textView.setText(response.name+" - "+response.place);

imageView.setImageBitmap(b);

return v;

layout1.java

     public class Layout1 extends AppCompatActivity implements TabLayout.OnTabSelectedListener {
    TabLayout tabLayout;
     ViewPager viewPager;
    ImageView imageView1, imageView2, imageView3;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_layout1);


            tabLayout = (TabLayout) findViewById(R.id.tablayout1);
            tabLayout.addTab(tabLayout.newTab().setText("Tab1"));
            tabLayout.addTab(tabLayout.newTab().setText("Tab2"));
            tabLayout.addTab(tabLayout.newTab().setText("Tab3"));


            tabLayout.setTabGravity(tabLayout.GRAVITY_FILL);


            viewPager = (ViewPager) findViewById(R.id.viewpager1);
            Pager adapter = new Pager(getSupportFragmentManager(), tabLayout.getTabCount());

            viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
            viewPager.setAdapter(adapter);
            tabLayout.setOnTabSelectedListener(this);
            viewPager.getCurrentItem();
            viewPager.setOffscreenPageLimit(3);


            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab1);
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    int position = tabLayout.getSelectedTabPosition();
                    switch (position) {

                        case 0:
                            File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            String pictureName = "image1" + ".jpg";
                            //  imageName(pictureName);
                            File imageFile = new File(file, pictureName);
                            Uri pictureUri = Uri.fromFile(imageFile);

                            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            i.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
                            startActivityForResult(i, 0);

                            break;

                        case 1:
                            File file2 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            String pictureName2 = "image2" + ".jpg";
                            File imageFile2 = new File(file2, pictureName2);
                            Uri pictureUri2 = Uri.fromFile(imageFile2);
                            Intent ii = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            ii.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri2);
                            startActivityForResult(ii, 1);
                            break;

                        case 2:
                            File file3 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            String pictureName3 = "image3" + ".jpg";
                            File imageFile3 = new File(file3, pictureName3);
                            Uri pictureUri3 = Uri.fromFile(imageFile3);
                            Intent iii = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            iii.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri3);
                            startActivityForResult(iii, 2);
                            break;
                    }
                }
            });
    }


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    imageView1 = (ImageView) findViewById(R.id.img1);
    imageView2 = (ImageView) findViewById(R.id.img2);
    imageView3 = (ImageView) findViewById(R.id.img3);


    if (requestCode == 0 && resultCode == RESULT_OK) {

        String photoPath = Environment.getExternalStorageDirectory() + "/Download/image1.jpg";
        galleryAddPic(photoPath);
        Bitmap bitmap1 = BitmapFactory.decodeFile(photoPath);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        final Bitmap b = BitmapFactory.decodeFile(photoPath, options);

        imageView1.setImageBitmap(b);
        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView1.buildDrawingCache();
                Bitmap image = imageView1.getDrawingCache();

                Bundle extras = new Bundle();
                Intent o = new Intent(Layout1.this, Information.class);
                extras.putParcelable("Bitmap", image);

                o.putExtras(extras);

                startActivity(o);

            }
        });


    } else if (requestCode == 1 && resultCode == RESULT_OK) {

        String photoPath = Environment.getExternalStorageDirectory() + "/Download/image2.jpg";
        galleryAddPic(photoPath);

        Bitmap bitmap2 = BitmapFactory.decodeFile(photoPath);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        final Bitmap b2 = BitmapFactory.decodeFile(photoPath, options);
        imageView2.setImageBitmap(b2);
        imageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView2.buildDrawingCache();
                Bitmap image = imageView2.getDrawingCache();

                Bundle extras = new Bundle();
                Intent o = new Intent(Layout1.this, Information.class);
                extras.putParcelable("Bitmap", image);
                o.putExtras(extras);
                startActivity(o);

            }
        });


    } else if (requestCode == 2 && resultCode == RESULT_OK) {


        String photoPath = Environment.getExternalStorageDirectory() + "/Download/image3.jpg";
        galleryAddPic(photoPath);
        Bitmap bitmap3 = BitmapFactory.decodeFile(photoPath);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        final Bitmap b3 = BitmapFactory.decodeFile(photoPath, options);
        imageView3.setImageBitmap(b3);
        imageView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView3.buildDrawingCache();
                Bitmap image = imageView3.getDrawingCache();

                Bundle extras = new Bundle();
                Intent o = new Intent(Layout1.this, Information.class);
                extras.putParcelable("Bitmap", image);
                o.putExtras(extras);
                startActivity(o);

            }
        });


    }

        }





private void galleryAddPic(String photoPath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(photoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}





@Override
public void onTabSelected(TabLayout.Tab tab) {


    viewPager.setCurrentItem(tab.getPosition());

}

@Override
public void onTabUnselected(TabLayout.Tab tab) {
    viewPager.setCurrentItem(tab.getPosition());

}

@Override
public void onTabReselected(TabLayout.Tab tab) {
    viewPager.setCurrentItem(tab.getPosition());

}

}

information.java

public class Information extends AppCompatActivity {

EditText text1,text2 ;
Button btn;
DataBaseHelper dataBaseHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_information);

    text1 = (EditText) findViewById(R.id.txt1);
    text2 = (EditText) findViewById(R.id.txt2);
    ImageView oo= (ImageView)findViewById(R.id.imageView99);

    btn = (Button) findViewById(R.id.btn1);
    Log.d("CLick", "123 INFO SAVED");
    addData();

    dataBaseHelper = new DataBaseHelper(this);


    Bundle extras = getIntent().getExtras();
    Bitmap bmp = (Bitmap) extras.getParcelable("Bitmap");
    oo.setImageBitmap(bmp);



}

public void addData(){
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dataBaseHelper.insertentry(text1.getText().toString(),text2.getText().toString());
            Toast.makeText(getApplicationContext(),"doneeeee",
                    Toast.LENGTH_LONG).show();
            Intent b = new Intent(Information.this,Layout1.class);
            startActivity(b);
        }
    });

}

日志猫:

09-13 15:35:42.550 22723-22723/com.example.mike.bigone12 E/SQLiteLog: (1) no such column: flag
09-13 15:35:42.550 22723-22723/com.example.mike.bigone12 D/AndroidRuntime: Shutting down VM
09-13 15:35:42.550 22723-22723/com.example.mike.bigone12 W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41ab0270)
09-13 15:35:42.560 22723-22723/com.example.mike.bigone12 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.example.mike.bigone12, PID: 22723
                                                                       android.database.sqlite.SQLiteException: no such column: flag (code 1): , while compiling: SELECT * FROM images WHERE flag =1
                                                                           at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                           at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                                                                           at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                                                                           at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                                           at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                                                                           at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
                                                                           at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
                                                                           at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
                                                                           at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
                                                                           at com.example.mike.bigone12.DataBaseHelper.getDataforTab1(DataBaseHelper.java:70)
                                                                           at com.example.mike.bigone12.Tab1.onCreateView(Tab1.java:33)
                                                                           at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
                                                                           at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
                                                                           at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
                                                                           at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
                                                                           at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1632)
                                                                           at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:637)
                                                                           at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
                                                                           at android.support.v4.view.ViewPager.populate(ViewPager.java:1235)
                                                                           at android.support.v4.view.ViewPager.populate(ViewPager.java:1083)
                                                                           at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1609)
                                                                           at android.view.View.measure(View.java:16518)
                                                                           at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
                                                                           at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
                                                                           at android.view.View.measure(View.java:16518)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                           at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
                                                                           at android.view.View.measure(View.java:16518)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                                           at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
                                                                           at android.view.View.measure(View.java:16518)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                           at android.view.View.measure(View.java:16518)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                                           at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
                                                                           at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
                                                                           at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
                                                                           at android.view.View.measure(View.java:16518)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                           at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2410)
                                                                           at android.view.View.measure(View.java:16518)
                                                                           at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1921)
                                                                           at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1114)
                                                                           at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1296)
                                                                           at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1001)
                                                                           at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5680)
                                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
                                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:574)
                                                                           at android.view.Choreographer.doFrame(Choreographer.java:544)
                                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
                                                                        at an

我为每个标签获取相同的信息我希望每个标签都有自己的信息!

只需使用 currentFragment.getClass().getName();获取片段名称并使用此名称查询您的数据库

DbResponse response = db.getData(currentFragment.getClass().getName());

然后

public DbResponse getData(String tabname) {
   DbResponse obj = new DbResponse();
   SQLiteDatabase db = this.getWritableDatabase();
   if(tabname.equals("Tab1")){
   Cursor cursor = db.rawQuery("select column1 from " + TABLE_NAME, null);
   }
   else if(tabname.equals("Tab2")){
   Cursor cursor = db.rawQuery("select column2 from " + TABLE_NAME, null);
   }
   else if(tabname.equals("Tab3")){
   Cursor cursor = db.rawQuery("select column3 from " + TABLE_NAME, null);
   }
  if (cursor.getCount() > 0) {
   cursor.moveToNext();
   obj.name = cursor.getString(cursor.getColumnIndex(NAME));
   obj.place = cursor.getString(cursor.getColumnIndex(PLACE));

}

 cursor.close();
 return obj;
 }

类似的东西

在 table 中使用整数数据类型创建一个字段和一个附加字段 插入时:

在你的activity中:

  public class Layout1 extends AppCompatActivity implements TabLayout.OnTabSelectedListener {
    TabLayout tabLayout;
     ViewPager viewPager;
    ImageView imageView1, imageView2, imageView3;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_layout1);


            tabLayout = (TabLayout) findViewById(R.id.tablayout1);
            tabLayout.addTab(tabLayout.newTab().setText("Tab1"));
            tabLayout.addTab(tabLayout.newTab().setText("Tab2"));
            tabLayout.addTab(tabLayout.newTab().setText("Tab3"));


            tabLayout.setTabGravity(tabLayout.GRAVITY_FILL);


            viewPager = (ViewPager) findViewById(R.id.viewpager1);
            Pager adapter = new Pager(getSupportFragmentManager(), tabLayout.getTabCount());

            viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
            viewPager.setAdapter(adapter);
            tabLayout.setOnTabSelectedListener(this);
            viewPager.getCurrentItem();
            viewPager.setOffscreenPageLimit(3);


            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab1);
            fab.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    int position = tabLayout.getSelectedTabPosition();
                    switch (position) {

                        case 0:
                            File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            String pictureName = "image1" + ".jpg";
                            //  imageName(pictureName);
                            File imageFile = new File(file, pictureName);
                            Uri pictureUri = Uri.fromFile(imageFile);

                            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            i.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
                            startActivityForResult(i, 0);

                            break;

                        case 1:
                            File file2 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            String pictureName2 = "image2" + ".jpg";
                            File imageFile2 = new File(file2, pictureName2);
                            Uri pictureUri2 = Uri.fromFile(imageFile2);
                            Intent ii = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            ii.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri2);
                            startActivityForResult(ii, 1);
                            break;

                        case 2:
                            File file3 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            String pictureName3 = "image3" + ".jpg";
                            File imageFile3 = new File(file3, pictureName3);
                            Uri pictureUri3 = Uri.fromFile(imageFile3);
                            Intent iii = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            iii.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri3);
                            startActivityForResult(iii, 2);
                            break;
                    }
                }
            });
    }


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    imageView1 = (ImageView) findViewById(R.id.img1);
    imageView2 = (ImageView) findViewById(R.id.img2);
    imageView3 = (ImageView) findViewById(R.id.img3);


    if (requestCode == 0 && resultCode == RESULT_OK) {

        String photoPath = Environment.getExternalStorageDirectory() + "/Download/image1.jpg";
        galleryAddPic(photoPath);
        Bitmap bitmap1 = BitmapFactory.decodeFile(photoPath);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        final Bitmap b = BitmapFactory.decodeFile(photoPath, options);

        imageView1.setImageBitmap(b);
        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView1.buildDrawingCache();
                Bitmap image = imageView1.getDrawingCache();

                Bundle extras = new Bundle();
                Intent o = new Intent(Layout1.this, Information.class);
                extras.putParcelable("Bitmap", image);
                extras.putInt("flag",1); 
                o.putExtras(extras);

                startActivity(o);

            }
        });


    } else if (requestCode == 1 && resultCode == RESULT_OK) {

        String photoPath = Environment.getExternalStorageDirectory() + "/Download/image2.jpg";
        galleryAddPic(photoPath);

        Bitmap bitmap2 = BitmapFactory.decodeFile(photoPath);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        final Bitmap b2 = BitmapFactory.decodeFile(photoPath, options);
        imageView2.setImageBitmap(b2);
        imageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView2.buildDrawingCache();
                Bitmap image = imageView2.getDrawingCache();

                Bundle extras = new Bundle();
                Intent o = new Intent(Layout1.this, Information.class);
                extras.putParcelable("Bitmap", image);
                extras.putInt("flag",2);  
                o.putExtras(extras);
                startActivity(o);

            }
        });


    } else if (requestCode == 2 && resultCode == RESULT_OK) {


        String photoPath = Environment.getExternalStorageDirectory() + "/Download/image3.jpg";
        galleryAddPic(photoPath);
        Bitmap bitmap3 = BitmapFactory.decodeFile(photoPath);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        final Bitmap b3 = BitmapFactory.decodeFile(photoPath, options);
        imageView3.setImageBitmap(b3);
        imageView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imageView3.buildDrawingCache();
                Bitmap image = imageView3.getDrawingCache();

                Bundle extras = new Bundle();
                Intent o = new Intent(Layout1.this, Information.class);
                extras.putParcelable("Bitmap", image);
                extras.putInt("flag",3);
                o.putExtras(extras);
                startActivity(o);

            }
        });


    }

        }





private void galleryAddPic(String photoPath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(photoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}





@Override
public void onTabSelected(TabLayout.Tab tab) {


    viewPager.setCurrentItem(tab.getPosition());

}

@Override
public void onTabUnselected(TabLayout.Tab tab) {
    viewPager.setCurrentItem(tab.getPosition());

}

@Override
public void onTabReselected(TabLayout.Tab tab) {
    viewPager.setCurrentItem(tab.getPosition());

}

}

在您的信息中Activity:

public class Information extends AppCompatActivity {

EditText text1,text2 ;
Button btn;
Integer flag;
DataBaseHelper dataBaseHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_information);

    text1 = (EditText) findViewById(R.id.txt1);
    text2 = (EditText) findViewById(R.id.txt2);
    ImageView oo= (ImageView)findViewById(R.id.imageView99);

    btn = (Button) findViewById(R.id.btn1);
    Log.d("CLick", "123 INFO SAVED");

    dataBaseHelper = new DataBaseHelper(this);


    Bundle extras = getIntent().getExtras();
    Bitmap bmp = (Bitmap) extras.getParcelable("Bitmap");
    flag=extras.getInt("flag");
    oo.setImageBitmap(bmp)'   
       btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dataBaseHelper.insertentry(text1.getText().toString(),text2.getText().toString(),flag);
            Toast.makeText(getApplicationContext(),"doneeeee",
                    Toast.LENGTH_LONG).show();
            Intent b = new Intent(Information.this,Layout1.class);
            startActivity(b);
        }
    });


}

就像你的第三个标签一样,你在插入时放了 3 然后在调用第一个标签的方法时你可以这样查询:

    public class DataBaseHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "big.db";
    public static final String TABLE_NAME = "images";
    public static final String NAME = "name";
    public static final String PLACE = "place";
    public static final String FLAG ="flag";


    public DataBaseHelper(Context context) {

        super(context, DATABASE_NAME, null, 1);
        SQLiteDatabase db = this.getWritableDatabase();

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_IMAGES_TABLE = "CREATE TABLE images ( " +
                "ID  INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "flag INTEGER, " +

                "name TEXT, " +
                "place TEXT )";

        db.execSQL(CREATE_IMAGES_TABLE);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("DROP TABLE IF EXISTS images");
        this.onCreate(db);
    }



    public void insertentry(String name, String place,Integer flag) {

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(NAME, name);
        contentValues.put(FLAG,flag)
        contentValues.put(PLACE, place);

        db.insert(TABLE_NAME, null, contentValues);
        db.close();

    }
     public DbResponse getDataforTab1() {
       DbResponse obj = new DbResponse();
       SQLiteDatabase db = this.getWritableDatabase();
       Cursor cursor = db.rawQuery("SELECT * FROM " + Table_Name + " WHERE " + FLAG + " =" + 1 + "",null);
      if (cursor.getCount() > 0) {
       cursor.moveToNext();
       obj.name = cursor.getString(cursor.getColumnIndex(NAME));
       obj.place = cursor.getString(cursor.getColumnIndex(PLACE));

    }

     cursor.close();
     return obj;
     }

//in 2nd Tab

    public DbResponse getDataforTab3() {
       DbResponse obj = new DbResponse();
       SQLiteDatabase db = this.getWritableDatabase();
       Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + "where"+FLAG+"=2 , null);
      if (cursor.getCount() > 0) {
       cursor.moveToNext();
       obj.name = cursor.getString(cursor.getColumnIndex(NAME));
       obj.place = cursor.getString(cursor.getColumnIndex(PLACE));

    }

     cursor.close();
     return obj;
     }

In 3rd Tab:

    public DbResponse getDataforTab3() {
       DbResponse obj = new DbResponse();
       SQLiteDatabase db = this.getWritableDatabase();
       Cursor cursor = db.rawQuery("select * from " + TABLE_NAME + "where"+FLAG+"=3, null);
      if (cursor.getCount() > 0) {
       cursor.moveToNext();
       obj.name = cursor.getString(cursor.getColumnIndex(NAME));
       obj.place = cursor.getString(cursor.getColumnIndex(PLACE));

    }

     cursor.close();
     return obj;
     }

您的 DBHelper Class:

就像你可以在你的片段中调用这个方法你可以将它设置为你的textview任何疑问都可以问