I'm trying to do a contextmenu in the fragment, but it does not work

245
March 31, 2017, at 03:15 AM

I'm trying to do a contextmenu in the fragment, but it does not work and this is my code.

public class FragmentHome extends Fragment {
private String DATABASE_NAME = "Alarm.sqlite";
private SQLiteDatabase Database;
ListView listView;
ArrayList<alarm> list;
AdapterAlarm adapterAlarm;
Intent intent;
AlarmManager alarmManager;
PendingIntent pendingIntent;


@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view= inflater.inflate(R.layout.fragment_fragment_home, container, false);
    registerForContextMenu(view.findViewById(R.id.lv));
    return  view;
}
@Override
public void onStart() {
    super.onStart();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    listView = (ListView)getView().findViewById(R.id.lv);
    //khoi tao arraylist va adapter
    list = new ArrayList<alarm>();
    adapterAlarm = new AdapterAlarm(list, getActivity());
    //set adapter len listview
    listView.setAdapter(adapterAlarm);
    //đăng ký context menu
    getData();
}
@Override
//create contextmenu
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    getActivity().getMenuInflater().inflate(R.menu.menu_listview_home, menu);
}
@Override
//catch the event on list
public boolean onContextItemSelected(MenuItem item) {
    //AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch(item.getItemId()) {
        case R.id.edit:
            // Do some stuff
            break;
        case R.id.delete:
            // Do some stuff
            break;
    }
    return super.onContextItemSelected(item);
}
}

Any quarterly answer is worthy

Rent Charter Buses Company
READ ALSO
Android request ACCESS_NOTIFICATION_POLICY and mute phone

Android request ACCESS_NOTIFICATION_POLICY and mute phone

I am a beginner Android developer and I have an interesting question at handI am trying to mute the phone with

1336
null object after valueEventListener

null object after valueEventListener

I am using Firebase valueEventListener and adding objects in OnDataChangeBut my list stays null

321
How clicking on a thumbnail image produces a larger image so quickly

How clicking on a thumbnail image produces a larger image so quickly

I am developing an android app which needs to load a big image quicklyUsing Instagram on Android I have noticed a feature they have that I cannot figure out how it works

242
Sqlite Database and Broadcast Receiver

Sqlite Database and Broadcast Receiver

Is it a good idea to access SQLite Database inside the Broadcast Receiver and perform operations (say reading from it and displaying a toast or changing the UI etc) on it

492