inflated
の長さのリストをボタン付きでcustom listview
に持っています。私はシングルbutton
をクリックしてシングル曲を演奏したい。 私はボタンクリックの位置を取得し、またプレイソングの方法で曲を渡しました。しかし、それはeventually
その曲を演奏していない。もし私がplaySong(1);
と設定すると、最初の曲が再生されます。しかし、私はplaySong(position);
を設定した場合、それはどのsong.Pleaseヘルプ曲を再生するカスタムLisviewからBuTTONをクリックして位置
public abstract class CustomAdapter extends BaseAdapter implements Filterable , SeekBar.OnSeekBarChangeListener {
Context context;
ArrayList<String> countryList;
ArrayList<String> mStringFilterList;
LayoutInflater inflter;
public ImageView img2;
Handler mHandler = new Handler();
private SeekBar songProgressBar;
public CustomAdapter(Context applicationContext, ArrayList<String> countryList) {
this.context = applicationContext;
this.countryList = countryList;
mStringFilterList = countryList;
inflter = (LayoutInflater.from(applicationContext));
}
@Override
public int getCount() {
return countryList.size();
}
public void updateData(ArrayList<String> countryList) {
this.countryList = countryList;
notifyDataSetChanged();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(final int position, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.list_itemss, null);
String hello = countryList.get(position);
Log.d("Hello",hello);
playSong(1);
String henno1 = String.valueOf(hello.length());
Log.d("hellya",henno1);
songProgressBar = (SeekBar) view.findViewById(R.id.songProgressBar);
TextView country = (TextView) view.findViewById(R.id.textView);
country.setText(hello);
songProgressBar.setOnSeekBarChangeListener(this);
songCurrentDurationLabel = (TextView) findViewById(R.id.songCurrentDurationLabel);
songTotalDurationLabel = (TextView) findViewById(R.id.songTotalDurationLabel);
img2 = (ImageView)view.findViewById(R.id.button3);
img2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(Main.this,"Position is --"+position,Toast.LENGTH_LONG).show();
int songIndex = position;
playSong(songIndex);
Log.d("song_index", String.valueOf(songIndex));
/*I GET THE INDEX IN LOG*/
if(mp.isPlaying()){
if(mp!=null){
mp.pause();
// Changing button image to play button
img2.setImageResource(R.drawable.playbutton);
}
}else{
// Resume song
if(mp!=null){
mp.start();
// Changing button image to pause button
img2.setImageResource(R.drawable.pausebutton);
}
}
Toast.makeText(Main.this,"Play Song",Toast.LENGTH_LONG).show();
}
});
ImageView img =(ImageView)view.findViewById(R.id.button);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(Main.this,"Added to Playlist",Toast.LENGTH_LONG).show();
file = new File(path.get(position));
customAdapter.notifyDataSetChanged();
}
});
return view;
}
public void playSong(int songIndex){
// Play song
Toast.makeText(Main.this,"Song is Playing",Toast.LENGTH_LONG).show();
int m =songIndex;
//i ALSO GET THE POSITION IN LOG ON BUTTON CLICK BUT SONG IS NOT PLAYING.
Log.d("Printsssss", String.valueOf(m));
try {
mp.start();
mp.reset();
mp.setDataSource(songsList.get(songIndex).get("songPath"));
mp.prepare();
mp.start();
updateProgressBar();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
thnku ..男!!!今すぐitzを再生 –