2014-03-25 3 views
1

알림을 시작하는 방법이 있습니다. 그러나 이제 버튼 컨텍스트 메뉴를 길게 눌러서 바인딩하고 싶습니다. 어떻게해야합니까?Android 길게 누르면 버튼 상황에 맞는 메뉴

public void ringtone(){ 
    try { 
     Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); 
     r.play(); 
    } catch (Exception e) { 
     e.printStackTrace(); 

    } 

답변

0
@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);//Menu Resource, Menu 
    return true; 
} 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.List1: 
      //List1 is a button in menu.xml 
      //it is the button you want to bind the method to 
      //call the function ringtone() fom here 
      ringtone(); 
      default: 
      return super.onOptionsItemSelected(item); 
    } 
} 

이미의 ContextMenu 만들었다 고 가정하고

android:id="@+id/List1" 
과의 버튼이
관련 문제