从原始文件夹播放声音与listview的每一行成比例

时间:2014-04-01 08:10:42

标签: android listview audio

我希望在下面的代码中播放原始文件夹中的声音文件与每行列表成比例,其意思是例如播放1.mp3与lorem并播放2.mp3与ipsum和...

我应该在代码中添加什么内容?

请帮帮我......

我的代码:

    public class InflatList extends ListActivity {
private TextView selection;
private static final String[] items = {"lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "morbi", "vel", "ligula", "vitae", "arcu", "placerat", "ante", "porttitor", "sodales", "pellentesque", "augue", "purus"};

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

    setListAdapter(new IconicAdapter());
    selection = (TextView)findViewById(R.id.selection);
  }

  //=====================
  //New Class Starts Here
  //=====================
  class IconicAdapter extends ArrayAdapter<String> {

    public IconicAdapter() {
        super(InflatList.this, R.layout.row, items);
    }

    public View getView(int position, View convertView, ViewGroup parent){
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.row, parent, false);

        TextView label = (TextView)row.findViewById(R.id.label);
        label.setText(items[position]);
        ImageView icon = (ImageView)row.findViewById(R.id.pic);
            ImageButton btnplay = (ImageButton)row.findViewById(R.id.btnplay);

        return(row);
    }
 }
 }

2 个答案:

答案 0 :(得分:0)

假设你早早完成了声音

所以你可以从 onListItemClick

获得关注
 @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

             // find which item clicked from the id,

            //Place your code here for play video




}

答案 1 :(得分:0)

假设文件是​​来自1.mp3的数字,2.mp3 ...用于1&#39; st,2&#39; nd元素......依此类推 (如果不同使用不同的逻辑来查找文件的名称)

@Override
protected void onListItemClick(ListView list, View view, int position, long id) {
    super.onListItemClick(list, view, position, id);
         String fname = String.value(position + 1);
         int resID=getResources().getIdentifier(fname, "raw", getPackageName());
         MediaPlayer mediaPlayer=MediaPlayer.create(this,resID);
         mediaPlayer.start();
}