2012-03-22 9 views
0

私はAndroidの音楽プレーヤーで作業しています。下のコードは、リストの特定の曲を長時間クリックしてダイアログボックスを表示するためのものです。しかし、何らかの形でこのケースでは機能しません。あなたは問題を理解してください?リストアイテムのコンテキストメニューを表示

public class ListQueue extends ListActivity{ 
// ListActivity l1= new ListActivity(); 
    public static final String MEDIA_PATH= new String("/sdcard/"); //path of the songs 
    public static List<String> songs = new ArrayList<String>(); //array name of the songs 
    public static int currentPosition = 0; //current position of the song in the List 
    public static String songName;   //name of the song 
    public static int duration;   //total duration of the song 
    public static MediaPlayer mp=new MediaPlayer(); 
    public String[] menuItems={"set as ringtone","delete","send","Crop","details"}; 
    public String[] songsarray; 
    public int i=0; 
    // public TextView textViewToChange=null; 
    // public static double n ; 

    @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.songlist); 

     //updates the song list 
     updateSongList(); 
    } 

    //update song list called in onCreate() 
    public void updateSongList(){ 
     File home=new File(MEDIA_PATH); 
     songs.clear(); 
     if(home.listFiles(new Mp3Filter()).length > 0){ 
      for(File file : home.listFiles(new Mp3Filter())){ 
       songs.add(file.getName()); 
       songsarray[i++]=file.getName(); 

       ArrayAdapter<String> songList = new ArrayAdapter<String>(this,R.layout.song_item,songs); 
       setListAdapter(songList); 
      } 
     } 


     registerForContextMenu(getListView()); 
    } 
    @Override 
    public void onCreateContextMenu(ContextMenu menu, View v, 
     ContextMenuInfo menuInfo) { 
     if (v.getId()==R.id.list) { 
     AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; 
     menu.setHeaderTitle(songsarray[info.position]); 
     // String[] menuItems = getResources().getStringArray(R.array.menu); 
     for (int i = 0; i<menuItems.length; i++) { 
      menu.add(Menu.NONE, i, i, menuItems[i]); 
     } 
     } 
    } 

答えて

0

あなたの状態が真でないと思います(if(v.getId()== R.id.list))。 したがって、onCreateContextMenu()メソッドでこの条件を削除します。

@Override 
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) 
{ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; 
     menu.setHeaderTitle(songsarray[info.position]); 
     // String[] menuItems = getResources().getStringArray(R.array.menu); 
     for (int i = 0; i<menuItems.length; i++) 
      menu.add(Menu.NONE, i, i, menuItems[i]); 
} 

onCreateConxtMenu()メソッドの代わりに上記のコードを試してください。

0

は。これらの変更を行ってみてください

@Override 
public void onCreateContextMenu(ContextMenu menu, View v, 
    ContextMenuInfo menuInfo) { 
    if (v.getId()==R.id.list) { 
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; 
    menu.setHeaderTitle(songsarray[info.position]); 
    // String[] menuItems = getResources().getStringArray(R.array.menu); 
    for (int i = 0; i<menuItems.length; i++) { 
     menu.add(Menu.NONE, i, i, menuItems[i]); 
    } 
    return true;<---(1) 
    } 
return false;<---(2) 
} 
関連する問題