title: How to use the same button(one button) to add items in fragment
body: <p><a href="https://i.stack.imgur.com/XRTb1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XRTb1.png" alt="Layout Image"></a></p>
  
  <p>I created a fragment layout. Now, i want to add data into a database and display into each fragments. I use a pop up menu which is to be share for each fragment. My problem is that how will a single button will add item into a database for the different fragment. Please help!</p>
  
  <p>Here my database operation</p>
  
  <pre><code>public class Db_operation_helper extends SQLiteOpenHelper {
  private static final String Database_name="database_name";
  private static final int Database_version=1;
   private static final String Monday_query=
      "CREATE TABLE "+ UserContract.Time_monday.Mon_tablename+"("+ UserContract.Time_monday.Mon_subject+" TEXT,"+
              UserContract.Time_monday.Mon_instructor+" TEXT,"+ UserContract.Time_monday.Mon_timeone+" TEXT,"+
              UserContract.Time_monday.Mon_timetwo+" TEXT);";
  private static final String Tuesday_query=
          "CREATE TABLE "+ UserContract.Time_tuesday.Tue_tablename+"("+ UserContract.Time_tuesday.Tue_subject+" TEXT,"+
                  UserContract.Time_tuesday.Tue_instructor+" TEXT,"+ UserContract.Time_tuesday.Tue_timeone+" TEXT,"+
                  UserContract.Time_tuesday.Tue_timetwo+" TEXT);";
  @Override
  public void onCreate(SQLiteDatabase db) {
      db.execSQL(Gradebook_Query);
      Log.e("Database Operation", "Table Grade Book Created");
      db.execSQL(Monday_query);
      Log.e("Database Operation", "Table Monday Created");
      db.execSQL(Tuesday_query);
   public void monday_add(String subject,String instructor,String timeone,String timetwo,SQLiteDatabase db)
  {
      ContentValues contentValues=new ContentValues();
      contentValues.put(UserContract.Time_monday.Mon_subject,subject);
      contentValues.put(UserContract.Time_monday.Mon_instructor,instructor);
      contentValues.put(UserContract.Time_monday.Mon_timeone,timeone);
      contentValues.put(UserContract.Time_monday.Mon_timetwo,timetwo);
      db.insert(UserContract.Time_monday.Mon_tablename, null, contentValues);
      Log.e("Database Operation", "One row is inserted into Time Table monday");
  }
  public void tuesday_add(String subject,String instructor,String timeone,String timetwo,SQLiteDatabase db)
  {
      ContentValues contentValues=new ContentValues();
      contentValues.put(UserContract.Time_tuesday.Tue_subject,subject);
      contentValues.put(UserContract.Time_tuesday.Tue_instructor,instructor);
      contentValues.put(UserContract.Time_tuesday.Tue_timeone,timeone);
      contentValues.put(UserContract.Time_tuesday.Tue_timetwo,timetwo);
      db.insert(UserContract.Time_tuesday.Tue_tablename, null, contentValues);
      Log.e("Database Operation", "One row is inserted into Time Table Tueday");
  }
  </code></pre>
  
  <p>Here's the contract class</p>
  
  <pre><code>public class UserContract {
  public static abstract class  Time_monday{
      public static final String Mon_subject="mon_subject";
      public static final String Mon_instructor="mon_instructor";
      public static final String Mon_timeone="mon_timeone";
      public static final String Mon_timetwo="mon_timetwo";
      public static final String Mon_tablename="mon_tablename";
  }
  public static abstract class  Time_tuesday{
      public static final String Tue_subject="tue_subject";
      public static final String Tue_instructor="tue_instructor";
      public static final String Tue_timeone="tue_timeone";
      public static final String Tue_timetwo="tue_timetwo";
      public static final String Tue_tablename="tue_tablename";
  }}
  </code></pre>
  
  <p>And,this is the pop up window class java</p>
  
  <pre><code>public class Popwindow_timetable extends Activity {
  EditText Subject, Instructor, Timeone, Timetwo;
  Context context=this;
  Db_operation_helper db_operation_helper;
  SQLiteDatabase sqLiteDatabase;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.popwindow);
      DisplayMetrics dm = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(dm);
      int width = dm.widthPixels;
      int height = dm.heightPixels;
      getWindow().setLayout((int) (width * .650), (int) (height * .4));
      Subject = (EditText) findViewById(R.id.subject);
      Instructor = (EditText) findViewById(R.id.instructor);
      Timeone = (EditText) findViewById(R.id.timeone);
      Timetwo = (EditText) findViewById(R.id.timetwo);
  }
  public void timetable_add(View view)
  {
      String subject=Subject.getText().toString();
      String instructor=Instructor.getText().toString();
      String timeone=Timeone.getText().toString();
      String timetwo=Timetwo.getText().toString();
      db_operation_helper=new Db_operation_helper(context);
      sqLiteDatabase=db_operation_helper.getWritableDatabase();
      db_operation_helper.monday_add(subject,instructor,timeone,timetwo,sqLiteDatabase);
      Toast.makeText(getBaseContext(),"DATA IS ADDED",Toast.LENGTH_LONG).show();
      db_operation_helper.close();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>In this java file, timetable_add() function will be call when the button is click .Here the data is added only to a monday table.But,i want to add data respectively to a fragment.My problem is that when the fragment is swap to another layout the data enter will be added to the another table in a database when the button is click. but i dont know how to implement the code in a button click, to add data into another table of database as the button is share by all the fragment.</p>