2017-09-09 10 views
0

私はシンプルな音楽プレーヤーを作っています.3つのテキストとイメージボタンを持つカスタムリストアダプターを作っています。リストを使ってサービスとやりとりするandroid

ダイアログボックスを表示するボタンにクリックリスナーを配置しました。ダイアログボックスにオプションキューがあります。このオプションは、音楽サービスの曲をキューに入れるために使用されます。私は知りたい サービスをリストにどのように接続できますか? 接続できない場合はどうすればこのキューボタンのアクションをMainActivityに送信できますか?以下は

私アダプターコードがところで私がバインドされたサービスを使用しています

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    LayoutInflater inflater = LayoutInflater.from(getContext()); 

    convertView = inflater.inflate(R.layout.songs_list, parent, false); 


    final Song song = getItem(position); 

    final ImageButton optionsImgBtn = convertView.findViewById(R.id.options_imgbbtn); 
    optionsImgBtn.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      PopupMenu optionnMenu = new PopupMenu(getContext(), view); 
      optionnMenu.getMenuInflater().inflate(R.menu.list_option, optionnMenu.getMenu()); 

      optionnMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 
       @Override 
       public boolean onMenuItemClick(MenuItem menuItem) { 
        if(menuItem.getItemId()==R.id.vd){ 



        }else if(menuItem.getItemId()==R.id.vdi){ 

        } 
        return true; 
       } 
      }); 
      optionnMenu.show(); 
     } 
    }); 

    TextView txtvDname = convertView.findViewById(R.id.dname_txtv); 
    TextView txtvArtist = convertView.findViewById(R.id.artist_txtv); 
    TextView txtvDuration = convertView.findViewById(R.id.duration_txtv); 



    txtvDname.setText(song.name); 
    txtvArtist.setText(song.artist); 
    txtvDuration.setText(getFormatedTime(Integer.parseInt(song.duration))); 

    return convertView; 
} 

です。

注:私はonItemLongClickListnerの使い方を知っていますが、私はそれを使用したくありません。私が作ったボタンを使いたいです。

Button on the right with bars is the button I want to use

答えて

0

私は解決策に私の自己を発見したと私はそれがJavaで新しいあなたのすべてのためにかなり参考になると思います。

アダプターの抽象クラスと抽象メソッドを作成するだけです。アダプタを初期化するアクティビティのメソッドを実装するよりも。

関連する問題