0

メディア プレーヤー アプリを作成しましたListViewが、その特定のメディア ファイルをどのように再生するかについて混乱しています。コードは次のとおりです。

package com.example.Quran;
public class MainActivity extends Activity {

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final ListView listview = (ListView) findViewById(R.id.listview);
    String[] values = new String[] { "Surah1", "Surah2", "Surah3",
        "Surah4", "Surah5", "Surah6", "Surah7", "Surah8",
        "Surah9", "Surah10" };

    final ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < values.length; ++i) {
      list.add(values[i]);
    }
    final StableArrayAdapter adapter = new StableArrayAdapter(this,
        android.R.layout.simple_list_item_1, list);
    listview.setAdapter(adapter);

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

      @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {

        // TODO Auto-generated method stub

    }

    });
  }

  private class StableArrayAdapter extends ArrayAdapter<String> {

    HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

    public StableArrayAdapter(Context context, int textViewResourceId,
        List<String> objects) {
      super(context, textViewResourceId, objects);
      for (int i = 0; i < objects.size(); ++i) {
        mIdMap.put(objects.get(i), i);
      }
    }

    @Override
    public long getItemId(int position) {
      String item = getItem(position);
      return mIdMap.get(item);
    }

    @Override
    public boolean hasStableIds() {
      return true;
    }

  }

} 

このコーランアプリの作成を手伝ってください。

4

2 に答える 2

0

ListViewこのようにメインアクティビティで 呼び出すだけです..

final ListView lv1 = (ListView) findViewById(R.id.listV_main);

その後、onclickListenerこのようなことをしてください

lv1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position,
                long id) {
            // TODO Auto-generated method stub

            if (position == 0) {
                // code specific to first list item

                Intent i = new Intent(ListViewImageActivity.this,
                        Video_play.class);
                i.putExtra("key_video", 1);
                ListViewImageActivity.this.startActivity(i);

            } else

            if (position == 1) {
                // code specific to second list item


                Intent i = new Intent(ListViewImageActivity.this,
                        Video_play.class);
                i.putExtra("key_video", 2);
                ListViewImageActivity.this.startActivity(i);
            } else

            if (position == 2) {
                // code specific to third list item


                Intent i = new Intent(ListViewImageActivity.this,
                        Video_play.class);
                i.putExtra("key_video", 3);
                ListViewImageActivity.this.startActivity(i);
            }

など... MediaPlayer(Audio/Video) クラスで次のようにします

final Button play_button = (Button) findViewById(R.id.btnPlay);
final VideoView myVideoView1 = (VideoView) findViewById(R.id.MyVidView);

その後、このコードを次の場所に配置します。

// Getting Key from List Item to Play Video
    Bundle mydata = getIntent().getExtras();
    myKey = mydata.getInt("key_video");



play_button.setOnClickListener(new OnClickListener() {

            @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (myKey) {
            case 1:
                myVideoView1.setVideoURI(Uri.parse("android.resource://"
                        + getPackageName() + "/" + R.raw.star));
                myVideoView1.start();
                play_button.setVisibility(View.GONE);
                myVideoView1.requestFocus();

                break;
            case 2:
                myVideoView1.setVideoURI(Uri.parse("android.resource://"
                        + getPackageName() + "/" + R.raw.abc));
                myVideoView1.start();
                play_button.setVisibility(View.GONE);
                myVideoView1.requestFocus();
                break;

            case 3:
                myVideoView1.setVideoURI(Uri.parse("android.resource://"
                        + getPackageName() + "/" + R.raw.sheep));
                myVideoView1.start();
                play_button.setVisibility(View.GONE);
                myVideoView1.requestFocus();
                break;


            default:
                myVideoView1.setVideoURI(Uri.parse("android.resource://"
                        + getPackageName() + "/" + R.raw.star));
                myVideoView1.start();
                play_button.setVisibility(View.GONE);
                myVideoView1.requestFocus();
            }

        }
    });
于 2013-10-13T11:40:19.797 に答える