You are in an adapter so you can't save item Views like that.
fastest, but probably not the best, solution is to set playM as final
so that you will be able to access the right button in the listener.
public class Adapter extends ArrayAdapter<Song> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.list_view, null);
}
final Song p = items.get(position);
if (p != null) {
TextView tt = (TextView) v.findViewById(R.id.textView1);
tt1 = (TextView) v.findViewById(R.id.textView2);
Button del = (Button) v.findViewById(R.id.button1);
final Button playM = (Button) v.findViewById(R.id.button2);
Button stopM = (Button) v.findViewById(R.id.button3);
String title = p.getTitle();
String singer = p.getSinger();
if (tt != null) {
tt.setText(title);
}
if (tt1 != null) {
tt1.setText(singer);
}
del.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
db.deleteSong(p);
}
});
playM.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//AudioManager manager = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
//if (!manager.isMusicActive()) {
playM.setText("Pause");
Intent svc=new Intent(getContext(), Music.class);
svc.putExtra("uri", tt1.getText().toString());
getContext().startService(svc);
//}
}
});
stopM.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
playM.setText("Play");
Intent svc=new Intent(getContext(), Music.class);
getContext().stopService(svc);
}
});
}
return v;
}
}