Add data in SQLite Database using Fragment in Android
<p>I am trying to Add data in SQLite Database using Fragment, but it's not Adding in Database and there is no error while running app.
My code in AddRoom Fragment :</p>

<pre><code>public class AddRoom extends Fragment implements View.OnClickListener {

DatabaseHotel myHotel;
Button bt_addRoom;
EditText ed_roomtype, ed_roomPrice, ed_noOfRoom;
View view;
Context context;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    myHotel = new DatabaseHotel(getActivity());
    view = inflater.inflate(R.layout.addroom, container, false);

    bt_addRoom = (Button)view.findViewById(R.id.bt_addroom);

    ed_roomtype = (EditText)view.findViewById(R.id.ed_roomtype);
    ed_roomPrice = (EditText)view.findViewById(R.id.ed_roomprice);
    ed_noOfRoom = (EditText)view.findViewById(R.id.ed_noofrooms);

    return view;
}

@Override
public void onClick(View v) {
    bt_addRoom.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addRoom();
        }
    });
}


private  void addRoom(){
    String roomType = ed_roomtype.getText().toString();
    int roomPrice = Integer.parseInt(ed_roomPrice.getText().toString());
    int noOfRoom = Integer.parseInt(ed_noOfRoom.getText().toString());

    boolean inserted = myHotel.addRoom(roomType, roomPrice, noOfRoom);
    if (inserted){
        Message.message(context, "Room Added Succeccfully");
    }else {
        Message.message(context, "Room Not Added!!");
    }
}
}
</code></pre>

<p>In My Database class : addRoom() method code:</p>

<pre><code>  public boolean addRoom(String roomType, int roomPrice, int numberOfRoom){
        SQLiteDatabase db = mydb.getReadableDatabase();
        ContentValues cv = new ContentValues();
        cv.put(Database.ROOM_TYPE, roomType);
        cv.put(Database.ROOM_PRICE, roomPrice);
        cv.put(Database.NUMBER_OF_ROOMS, numberOfRoom);
        try {
            long result = db.insert(Database.ROOM_TABLE,null, cv);
            if (result == -1){
                return false;
            }else {
                return true;
            }
         }catch (SQLException e){
            Message.message(context, e+"");
        }
        return true;
    }
</code></pre>