I need help making a longpress Context menu

All your problems with Audio, Video and Images.

I need help making a longpress Context menu

Postby vamp6x6x6x » Mon Jan 31, 2011 3:47 pm

Basiclly I need help making it so people can longpress on a button and choose to set as ringtone or notfication tone.

here is some of my code I use so far for the sound:

Code: Select all
MediaPlayer mpButtonClick;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
      //set up the button sounds
  mpButtonClick = MediaPlayer.create(this, R.raw.money);
      
      Button bmoney = (Button) findViewById(R.id.money);
      bmoney.setOnClickListener(new View.OnClickListener() {
         
         @Override
         public void onClick(View v) {
            // TODO Auto-generated method stub
            mpButtonClick.start();
            
         }
      });
vamp6x6x6x
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 31, 2011 3:33 pm

Top

Re: I need help making a longpress Context menu

Postby imbroken » Mon Jan 31, 2011 10:56 pm

you could implement the onLongClickListener Interface

http://developer.android.com/reference/ ... tener.html
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Re: I need help making a longpress Context menu

Postby Jems » Mon Jan 31, 2011 11:30 pm

There is an entire existing architecture for creating and showing context menus, read:
http://developer.android.com/guide/topics/ui/menus.html
Jems
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Thu Dec 09, 2010 7:42 pm

Re: I need help making a longpress Context menu

Postby vamp6x6x6x » Tue Feb 01, 2011 12:21 am

Jems wrote:There is an entire existing architecture for creating and showing context menus, read:
http://developer.android.com/guide/topics/ui/menus.html


I actually tried by adding this after my sound:

Code: Select all
Button btn = (Button) findViewById(R.id.money);
    Button registerForContextMenu;

   @Override
   public void onCreateContextMenu(ContextMenu menu, View v,
         ContextMenuInfo menuInfo) {
      // TODO Auto-generated method stub
      super.onCreateContextMenu(menu, v, menuInfo);
      menu.setHeaderTitle("Context Menu");
      menu.add(0, v.getId(), 0, "Action 1");
      menu.add(0, v.getId(), 0, "Action 2");
   }



but I got a force close.
vamp6x6x6x
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 31, 2011 3:33 pm

Re: I need help making a longpress Context menu

Postby vamp6x6x6x » Tue Feb 01, 2011 8:42 am

Ok, so now after reading I do actually have a menu on long press like I wanted...the only problem is that it doesn't actually get the sound file and save it

I am wondering what did I do wrong now? Here is the code I used:

Code: Select all
Button SoundButton1 = (Button) findViewById(R.id.money); 
        registerForContextMenu(SoundButton1);
    }

    @Override 
       public void onCreateContextMenu(ContextMenu menu, View v,
               ContextMenuInfo menuInfo) {
           super.onCreateContextMenu(menu, v, menuInfo);
           menu.setHeaderTitle("Save as...");
           menu.add(0, MENU_RINGTONE, 0, "Ringtone");
           menu.add(0, MENU_NOTIFICATION, 0, "Notification");
   }

    @Override 
       public boolean onContextItemSelected(MenuItem item) { 
           if(item.getTitle()=="Ringtone"){function1(item.getItemId());} 
           else if(item.getTitle()=="Notification"){function2(item.getItemId());} 
           else {return false;} 
       return true; 
       } 
    
       public void function1(int id){ 
           Toast.makeText(this, "Ringtone saved", Toast.LENGTH_SHORT).show(); 
       } 
       public void function2(int id){ 
           Toast.makeText(this, "Notification saved", Toast.LENGTH_SHORT).show(); 
       } 
vamp6x6x6x
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 31, 2011 3:33 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 17 guests