Q: ContextMenu not working for tabs I have 2 tabs with context menu but when the one is working the other wont work its on the same page but on different tab. Here is my codes thanks I cant make it to work.
The page with tabs
public class OwnerTabs extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
SharedPreferences pref;
SharedPreferences.Editor editor;

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    pref = getSharedPreferences("Login.conf", Context.MODE_PRIVATE);

    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent in = new Intent(OwnerTabs.this, InsertActivity.class);
            startActivity(in);
        }
    });

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu_main,menu);
    return super.onCreateOptionsMenu(menu);
}



@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if(id == R.id.action_logout){
        editor = pref.edit();
        editor.clear();
        editor.commit();
        Intent in = new Intent (getApplicationContext(), MainActivity.class);
        startActivity(in);
        finish();
    }

    return super.onOptionsItemSelected(item);
}


public static class PlaceholderFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    private static final String ARG_SECTION_NUMBER = "section_number";

    public PlaceholderFragment() {
    }

    public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        if (getArguments().getInt(ARG_SECTION_NUMBER) == 1){
            View rootView = inflater.inflate(R.layout.content_ownerhome, container, false);
            return rootView;
        }
        else if(getArguments().getInt(ARG_SECTION_NUMBER) == 2){
            View rootView = inflater.inflate(R.layout.content_rented, container, false);
            return rootView;
        }
        else if(getArguments().getInt(ARG_SECTION_NUMBER) == 3){
            View rootView = inflater.inflate(R.layout.fragment_owner_tabs, container, false);
            TextView textView = (TextView) rootView.findViewById(R.id.section_label);
            textView.setText("This content is under construction. Thank you!!");
            return rootView;
        }
        else {

            View rootView = inflater.inflate(R.layout.fragment_owner_tabs, container, false);
            TextView textView = (TextView) rootView.findViewById(R.id.section_label);
            textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
            return rootView;
        }
    }
}

public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return PlaceholderFragment.newInstance(position + 1);
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 3;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "Your Cars";
            case 1:
                return "Pending Cars";
            case 2:
                return "GPS";
        }
        return null;
    }
}
}

FirstTab
public class ownerFragment extends Fragment implements AsyncResponse, AdapterView.OnItemClickListener {
final String TAG = this.getClass().getName();
private ArrayList<Cars> carList;
private ListView lvCars;
private FunDapter<Cars> adapter;
SharedPreferences pref;
private String LOG = "ownerhome";
TextView tvUser;


@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.list_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    final Cars selectedCar = adapter.getItem(info.position);

    if (item.getItemId() == R.id.menuUpdate) {
        Intent in = new Intent(getActivity(), UpdateActivty.class);
        in.putExtra("cars", selectedCar);
        startActivity(in);

    } else if (item.getItemId() == R.id.menuDelete) {
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
        alert.setMessage("Are you sure to remove " + selectedCar.Car_Model + "?");
        alert.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                carList.remove(selectedCar);
                adapter.notifyDataSetChanged();

                HashMap postData = new HashMap();
                postData.put("Car_No", "" + selectedCar.Car_No);
                postData.put("mobile", "android");


                PostResponseAsyncTask taskPost = new PostResponseAsyncTask(getActivity(), postData, new AsyncResponse() {
                    @Override
                    public void processFinish(String s) {
                        Log.d(TAG, s);
                        if (s.contains("success")) {
                            Toast.makeText(getActivity().getApplicationContext(), "Car deleted!!", Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(getActivity().getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                taskPost.execute("http://carkila.esy.es/delete.php");
            }
        });
        alert.setNegativeButton("Cancel", null);
        alert.show();
    }

    return super.onContextItemSelected(item);
}

ContextMenu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.kun.carkila.ListActivity">
<item
android:id="@+id/menuUpdate"
android:orderInCategory="1"
android:title="Update"
app:showAsAction="never" />
<item
    android:id="@+id/menuDelete"
    android:orderInCategory="2"
    android:title="Delete"
    app:showAsAction="never" />
</menu>

Second Tab
public class rentedActivityFragment extends Fragment implements AsyncResponse, AdapterView.OnItemClickListener {
final String TAG = this.getClass().getName();
private ArrayList<RentedCars> carList;
private ListView lvRented;
private FunDapter<RentedCars> adapter;
SharedPreferences pref;


public rentedActivityFragment() {
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.reject_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    final RentedCars selectedCar = adapter.getItem(info.position);


    if(item.getItemId() == R.id.menuAccept){
        Intent in = new Intent(getActivity(), ownerAccept.class);
        in.putExtra("cars", selectedCar);
        startActivity(in);
    }else if (item.getItemId()==R.id.menuReject){
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
        alert.setMessage("Are you sure to reject "+selectedCar.carModel +"?");
        alert.setPositiveButton("Reject", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                carList.remove(selectedCar);
                adapter.notifyDataSetChanged();

                HashMap postData = new HashMap();
                postData.put("resID", "" + selectedCar.resID);
                postData.put("mobile", "android");
                PostResponseAsyncTask taskPost = new PostResponseAsyncTask(getActivity(), postData, new AsyncResponse() {
                    @Override
                    public void processFinish(String s) {
                        Log.d(TAG, s);
                        if (s.contains("success")) {
                            Toast.makeText(getActivity().getApplicationContext(), "Reservation rejected", Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(getActivity().getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                taskPost.execute("http://carkila.esy.es/rejectrent.php");
            }
        });
        alert.setNegativeButton("Cancel",null);
        alert.show();
    }

return super.onContextItemSelected(item);
}

Context Menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.kun.carkila.ListActivity">
<item
android:id="@+id/menuAccept"
android:orderInCategory="1"
android:title="Accept"
app:showAsAction="never" />
<item
    android:id="@+id/menuReject"
    android:orderInCategory="2"
    android:title="Reject"
    app:showAsAction="never" />
</menu>

Thanks guys in advance. :D
