I am making an android application that needs to use a ListView
. I want to add a menubutton that says \"Add to list\" and once the user presses that menubutton,
Adapter:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.beans.SongInfo;
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList data1;
private static LayoutInflater inflater=null;
//public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList d) {
activity = a;
data1=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data1.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView)vi.findViewById(R.id.title); // title
TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
SongInfo song=data1.get(position);
// Setting all values in listview
title.setText(song.getTitle());
artist.setText(song.getArtist());
duration.setText(song.getDuration());
if(song.getArtist().equalsIgnoreCase("Adele")){
thumb_image.setImageResource(R.drawable.rihanna);
}else if(song.getArtist().equalsIgnoreCase("Rihanna")){
thumb_image.setImageResource(R.drawable.rihanna);
}else if(song.getArtist().equalsIgnoreCase("Eminem")){
thumb_image.setImageResource(R.drawable.rihanna);
}else if(song.getArtist().equalsIgnoreCase("Michael Jackson")){
thumb_image.setImageResource(R.drawable.rihanna);
}
// imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
return vi;
}
}