-1

I was working for my college project, for a typical user interaction app . I have implemented a button that upon a long click will open up a floating contextual menu . Is there any way to open this menu upon a single click .I have checked around the web but I couldn't solve this issue . thank your for your time.

public class MainActivity extends ActionBarActivity {

Button b1;
RelativeLayout ourlayout;
String s1="@string/menu_add";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    b1 = (Button)findViewById(R.id.button1);

    registerForContextMenu(b1);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}





//////////////////////////////////////////////////////////////

public void onCreateContextMenu(ContextMenu menu, View v,
           ContextMenuInfo menuInfo) {
          // TODO Auto-generated method stub
          super.onCreateContextMenu(menu, v, menuInfo);
          getMenuInflater().inflate(R.menu.net, menu);
             menu.setHeaderTitle("Select your service provider");
         }
 @Override
 public boolean onContextItemSelected(MenuItem item) {

      switch (item.getItemId()) {


  }
  return super.onOptionsItemSelected(item);
 }

}

  • possible duplicate of [Android: Context menu on single click](http://stackoverflow.com/questions/6435073/android-context-menu-on-single-click) – Mike M. Sep 17 '14 at 05:11

2 Answers2

0

read about it Creating context menu at android developer, they also has sample code there with proper exlanations.

Techfist
  • 4,314
  • 6
  • 22
  • 32
0

For accomplishing your task try to use dialog Box instead of using Context Menu.

Context menu open on long press but dialog box will open on single click and on long click also. and after opening the dialog box you can get the data from dialog also.

mithileshssingh
  • 275
  • 3
  • 16