プレーヤー名のリストを保持するMainActivityを作成しました。そのlist_itemをクリックすると、クリックされたアイテムごとにsetTag()メソッドが必要ですSubActivity.In SubActivity MediaPlayerを実装する方法とそれらのタグを取得する方法。ListView内の各listItemに対してsetTag()メソッドを設定する方法
MainActivity:
public class MainActivity extends AppCompatActivity {
String[] audioTitels;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
audioTitels = res.getStringArray(R.array.audio_list);
listView = (ListView) findViewById(R.id.listView);
AudioAdapter audioAdapter = new AudioAdapter(this,audioTitels);
listView.setAdapter(audioAdapter);
listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch (i){
case 0 :
System.out.println("Value of song0 :"+ audioTitels[i]);
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 1:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 2:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 3:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 4:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 5:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 6:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 7:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 8:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 9:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 10:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 11:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 12:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 13:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 14:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 15:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 16:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 17:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 18:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 19:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 20:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 21:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 22:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 23:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 24:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 25:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 26:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 27:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 28:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 29:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 30:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 31:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 32:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 33:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 34:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 35:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 36:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 37:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 38:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 39:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 40:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 41:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 42:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 43:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 44:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 45:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 46:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 47:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 48:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 49:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 50:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 51:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 52:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 53:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 54:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 55:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 56:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 57:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 58:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 59:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 60:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 61:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 62:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 63:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 64:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 65:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 66:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 67:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 68:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 69:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 70:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 71:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 72:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 73:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 74:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 75:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 76:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 77:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 78:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 79:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 80:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 81:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 82:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 83:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 84:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 85:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 86:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 87:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 88:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 89:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 90:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 91:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 92:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 93:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 94:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 95:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 96:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 97:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 98:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 99:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 100:
System.out.println("Value of song100 :"+ audioTitels[i]);
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 101:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 102:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 103:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 104:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 105:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 106:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 107:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 108:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 109:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 110:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 111:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 112:
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
case 113:
System.out.println("Value of song113 :"+ audioTitels[i]);
Toast.makeText(MainActivity.this,"Song to Play",Toast.LENGTH_LONG).show();
break;
}
}
});
}
class AudioAdapter extends ArrayAdapter<String>{
Context context;
String[] myTitles;
AudioAdapter(Context c,String[] titles){
super(c,R.layout.single_audio,R.id.audioText,titles);
this.context = c;
this.myTitles = titles;
}
@Override
public View getView(int position, View convertView, ViewGroup
parent) {
View row = convertView;
if(row == null){
LayoutInflater layoutInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row =
layoutInflater.inflate(R.layout.single_audio,parent,false);
}
//getting refernce to the textview
TextView myTitle = (TextView)
row.findViewById(R.id.audioText);
myTitle.setText(myTitles[position]);
myTitle.setAnimation(AnimationUtils.loadAnimation(context,R.anim.list_animation));
return row;
}
}
}
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.xyz.listviewaudio.MainActivity"
android:weightSum="1">
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="430dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_weight="0.88">
</ListView>
</LinearLayout>
single_audio.xml:あなたはこのようなgetViewメソッドでクリックイベントを実行することができ
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:textAlignment="gravity"
android:layout_marginBottom="16dp"
android:id="@+id/audioText"/>
</RelativeLayout>
スイッチに113個のケースが必要な理由を説明できますか? – pskink
@pskink私はこのhttp://xyzt.com/plugins/quran/001.mp3のようなurl_pathを持っています。このsetTag( "001.mp3")のようなタグを( "114.mp3")まで設定し、これらのタグを取得し、これらのタグをSubactivityのURLに連結して祈りをする必要があります。 –
'setTag(String.format("%03d "、i)+" .mp3 ")'を使うだけです。それは3桁の文字列としてあなたの番号を与えます –