1.

I want to build one feature in my app where a user performs a long press on a contact it will show option like make Call and send SMS. How we can do that.

Answer»

In android application when user long press on any content it will SHOW an option to PERFORM ACTION this can be done using Context Menu. In your scenario, if user long presses on any contact we can show him a context menu with two options “MakeCall” and “Send SMS”. Please find below code for check how to implement a Context menu in our application:

For adding context menu in our application we NEED register View who is going to display data at a long press on it. We will create registerForContextMenu(View) for register view in our ACTIVITY and we need to override onCreateContextMenu() in our activity for displaying option to a user when the view has been long press by the user. In our scenario, Listview is having a list of contact so we will register Listview here. When user long press on any contact it call onCreateContaxtMenu method and show option like MakeCall and SendSMS. Please find below code for more detail:

Listview listview  = (ListView) findViewById(R.id.listShow);     registerForContextMenu(listview); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {     super.onCreateContextMenu(menu, v, menuInfo);     menu.setHeaderTitle("Context Menu");     menu.add(0, v.getId(), 0, "Make Call");     menu.add(0, v.getId(), 0, "Send SMS");


Discussion

No Comment Found

Related InterviewSolutions