I have a ListView that is contained in a fragment. When an item is clicked on the listview I want it to execute some code but the code that is executed depends on which item on the List was clicked. Here is my code for the fragment that contains the ListView:
public class ListViewer extends Fragment {
private ListView list;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInsanceState) {
View v = inflater.inflate(R.layout.activity_list_view, container, false);
Player player_data[] = new Player[] {
new Player(R.drawable.bschenn1, "Brayden Schenn", "Age: 21, Drafted 5th overall by LA King in 2009", "Center - #10"),
new Player(R.drawable.giroux, "Claude Giroux", "Age: 25, Drafted 22nd overall by Philadelphia Flyers in 2006", "Center - #28"),
new Player(R.drawable.hartnell, "Scott Hartnell", "Age: 30, Drafted 6th overall by Nashville Predators in 2000", "Left Wing - #19")
};
PlayerAdapter adapter = new PlayerAdapter(getActivity(), R.layout.list_row, player_data);
list = (ListView)v.findViewById(R.id.list);
View header = (View)inflater.inflate(R.layout.listview_header_row, null);
list.addHeaderView(header);
list.setAdapter(adapter);
return v;
}
}
Here is the code to the Adapter:
public class PlayerAdapter extends ArrayAdapter<Player> {
Context context;
int layoutResourceId;
Player data[] = null;
public PlayerAdapter(Context context, int layoutResourceId, Player[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
PlayerHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new PlayerHolder();
holder.imageIcon = (ImageView)row.findViewById(R.id.list_image);
holder.txtplayerName = (TextView)row.findViewById(R.id.title);
holder.txtageDraft = (TextView)row.findViewById(R.id.artist);
holder.txtpositionSNum = (TextView)row.findViewById(R.id.duration);
row.setTag(holder);
} else {
holder = (PlayerHolder)row.getTag();
}
Player player = data[position];
holder.imageIcon.setImageResource(player.image);
holder.txtplayerName.setText(player.playerName);
holder.txtageDraft.setText(player.ageDraft);
holder.txtpositionSNum.setText(player.positionSweaterNum);
return row;
}
static class PlayerHolder {
ImageView imageIcon;
TextView txtplayerName;
TextView txtageDraft;
TextView txtpositionSNum;
}
}
Any help is much appreciated.
You should add a listener to the listview to detect touch events.
list.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView parentView, View childView, int position, long id)
{
//here you have the position so you can do whatever you want with this item
}
});
You need to add OnItemClickListener to your list object:
list.setOnItemClickListener( new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
}
});
}
Related
I am trying to get the total of numbers in an sql table,
i first connected between android and sql but i can't
sum the numbers in the table column and show them
in a textview,like i want to get the total
of numbers in a column then
display them in a text view
,can someone help me with this task?
here is the code i used for
the listview
public class MyAppAdapter extends BaseAdapter //has a class viewholder which holds
{
public class ViewHolder
{
TextView textDate;
TextView textTotal;
TextView textLastTotal;
TextView textCount;
TextView textTaxs;
}
public List<ClassListItems2> parkingList;
public Context context;
ArrayList<ClassListItems2> arraylist;
private MyAppAdapter(List<ClassListItems2> apps, Context context)
{
this.parkingList = apps;
this.context = context;
arraylist = new ArrayList<ClassListItems2>();
arraylist.addAll(parkingList);
}
#Override
public int getCount() {
return parkingList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) // inflating the layout and initializing widgets
{
View rowView = convertView;
ViewHolder viewHolder= null;
if (rowView == null)
{
LayoutInflater inflater = getLayoutInflater();
rowView = inflater.inflate(R.layout.listcontent2, parent, false);
viewHolder = new ViewHolder();
viewHolder.textDate = (TextView) rowView.findViewById(R.id.date);
viewHolder.textLastTotal = (TextView) rowView.findViewById(R.id.lasttotal);
viewHolder.textTaxs = (TextView) rowView.findViewById(R.id.date3);
viewHolder.textCount = (TextView) rowView.findViewById(R.id.InvoicescCount);
viewHolder.textTotal = (TextView) rowView.findViewById(R.id.total);
rowView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder) convertView.getTag();
}
// here setting up names and images
viewHolder.textDate.setText(parkingList.get(position).getDate()+"");
viewHolder.textTotal.setText(parkingList.get(position).getTotal());
viewHolder.textLastTotal.setText(parkingList.get(position).getLasttotal());
viewHolder.textTaxs.setText(parkingList.get(position).getTaxs());
viewHolder.textCount.setText(parkingList.get(position).getInvoicecount());
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//What happens when you click on a place!
}
});
return rowView;
}
This Adapter is feed with a Collection (List) in his constructor.
To know total numbers, in Activity/Fragment that handle that Collection use:
parkingList.size()
To get sum:
float total;
for (ClassListItems2 actualItem : parkingList) {
total += actualItem.getTotal()
}
All of this logic must be executed in Activity/Fragment, never in Adapter because the Adapter only got presentation/visual logic.
I'm trying to implement an Android app for sudoku game, and i created a customized adapter for that. i want make edit text for cells the user is allowed to modify, and textview for cell filled by the program, the number of ediTexts and textViews will be random. how do specify that in the adapter ?
This is my adapter :
public class SodukuAdapter extends BaseAdapter {
ArrayList<String> items;
static Activity mActivity;
private static LayoutInflater inflater = null;
public SodukuAdapter (Activity activity, ArrayList<String> tempTitle,) {
mActivity = activity;
items = tempTitle;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public final int getCount() {
return items.size();
}
#Override
public final Object getItem(int position) {
return items.get(position);
}
#Override
public final long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = null;
v = inflater.inflate(R.layout.item, null);
EditText et = (EditText) v.findViewById(R.id.et);
et.setText(items.get(position));
return v;
}
}
You can place both views in the same parent (e. g. parent is a RelativeLayout or a FrameLayout) so they are on top of each other. Than you simply hide one of them and show the other using setVisibility() in your getView() method of the adapter.
Of course you would need a datasource object which keeps track of whether a view should show the TextView or the EditText:
class SodokuItem {
public boolean isStatic;
public String text;
}
...
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = inflater.inflate(R.layout.item, null);
SodokuItem item = items.get(position);
EditText et = (EditText) v.findViewById(R.id.et);
TextView tv = (TextView) v.findViewById(R.id.tv);
if(item.isStatic){
et.setVisibility(GONE);
tv.setText(item.text);
}else{
tv.setVisibility(GONE);
et.setText(item.text);
}
return v;
}
I'm new at android. and I want to load a new template which contains two button on a selected item of grid view object.
Is that possible.
I added a gridview to my project and by using base adapter a template was loaded to each item of gridview. But what I want is that when I clicked an item of gridview, I want to load a new template (layout) to the selected item.
THE PROBLEM WAS SOLVED, followings are the edited codes
Base Adapter
public class KategoriAdapter extends BaseAdapter{
private Context mContext;
private String[] categoryValues;
private Bitmap[] pictures;
//indicate that positon for new template
private int mNewTemplatePos = -1;
public KategoriAdapter(Context context, String[] categoryValues, Bitmap[] pictures) {
this.mContext = context;
this.categoryValues = categoryValues;
this.pictures = pictures;
}
//apply new template to positon
public void useNewTemplate(int pos) {
mNewTemplatePos =pos;
//notiy list that data has changed and the list will refresh ui itself.
notifyDataSetChanged();
}
#Override
public int getCount() {
return categoryValues.length;
}
#Override
public Object getItem(int possition) {
return null;
}
#Override
public long getItemId(int possition) {
return 0;
}
#Override
public View getView(int possition, View convertView, ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int posId = mNewTemplatePos;
if (convertView == null){
if (mNewTemplatePos ==possition){
convertView = getNewTemplate(inflater,possition);
}else {
convertView = getNormalTemplate(inflater,possition);
}
}else {
if (posId==possition){
convertView = getNewTemplate(inflater,possition);
}else{
convertView = getNormalTemplate(inflater,possition);
}
}
return convertView;
}
private View getNormalTemplate(LayoutInflater inflater, int possition) {
final View grid = inflater.inflate(R.layout.kategoriler_list_item, null);
TextView cName = (TextView) grid.findViewById(R.id.grid_item_ad);
ImageView categoryPictures = (ImageView) grid.findViewById(R.id.grid_item_resim);
cName.setText(categoryValues[possition]);
categoryPictures.setImageBitmap(pictures[possition]);
return grid;
}
private View getNewTemplate(LayoutInflater inflater, int possition) {
final View grid = inflater.inflate(R.layout.kategori_secenek_template, null);
TextView cName = (TextView) grid.findViewById(R.id.grid_item_ad);
cName.setText(categoryValues[possition]);
Button btn_nesne_tani = (Button) grid.findViewById(R.id.btn_nesneleri_taniyalim);
Button btn_cumle_kur = (Button) grid.findViewById(R.id.btn_cumle_kuralim);
btn_nesne_tani.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext,"nesne",Toast.LENGTH_SHORT).show();
}
});
btn_cumle_kur.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext,"cümle",Toast.LENGTH_SHORT).show();
}
});
return grid;
}
}
KategoriActivity.java
.....
final KategoriAdapter adapter = new KategoriAdapter(getApplicationContext(), mKategoriler, kategoriResimleri);
grid=(GridView)findViewById(R.id.gv_kategoriler);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
adapter.useNewTemplate(position);
Toast.makeText(getApplicationContext(), mKategoriler[position].toString(),Toast.LENGTH_SHORT).show();
}
});
}
I have rewrite your KategoriAdapter class:
public class KategoriAdapter extends BaseAdapter {
private Context mContext;
private final String[] categoryValues;
private final Bitmap[] pictures;
//indicate that positon in list are all use new template
private List<Integer> mNewTemplatePos;
public ImageView categoryPictures;
//indicate that this is normal template view
private final String NORMAL_TEMPLATE = "NORMAL_TEMPLATE";
//indicate that this is new template view
private final String NEW_TEMPLATE = "NEW_TEMPLATE";
public KategoriAdapter(Context context, String[] categoryValues, Bitmap[] pictures) {
this.mContext = context;
this.categoryValues = categoryValues;
this.pictures = pictures;
this.mNewTemplatePos = new ArrayList<>();
}
//apply new template to positon
public void useNewTemplate(int pos) {
mNewTemplatePos.add(pos);
//notiy list that data has changed and the list will refresh ui itself.
notifyDataSetChanged();
}
#Override
public int getCount() {
return categoryValues.length;
}
#Override
public Object getItem(int possition) {
return null;
}
#Override
public long getItemId(int possition) {
return 0;
}
#Override
public View getView(int possition, View convertView, ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
if (mNewTemplatePos.contains(possition)) {
convertView = getNewTemplate(inflater, possition);
//use tag to indicate the type of the template
convertView.setTag(NEW_TEMPLATE);
} else {
convertView = getNormalTemplate(inflater, possition);
convertView.setTag(NORMAL_TEMPLATE);
}
} else {
switch ((String) convertView.getTag()) {
case NORMAL_TEMPLATE:
//convertView is the normal template view but you need a new template view in possition
if (mNewTemplatePos.contains(possition))
convertView = getNewTemplate(inflater, possition);
break;
case NEW_TEMPLATE:
//convertView is the new template view but you need a normal template view in possition
if (!mNewTemplatePos.contains(possition))
convertView = getNormalTemplate(inflater, possition);
break;
}
}
return convertView;
}
private View getNormalTemplate(LayoutInflater inflater, int possition) {
View grid = inflater.inflate(R.layout.kategoriler_list_item, null);
TextView cName = (TextView) grid.findViewById(R.id.grid_item_ad);
categoryPictures = (ImageView) grid.findViewById(R.id.grid_item_resim);
cName.setText(categoryValues[possition]);
categoryPictures.setImageBitmap(pictures[possition]);
return grid;
}
private View getNewTemplate(LayoutInflater inflater, int possition) {
// TODO: 31/08/16 inflate you new template view layout here
return youNewTemplateView;
}
}
You should determine wether if current contentView is the right template type in getView() because contentView may be one of the new template in your list when it is not null.It is convenient to use tag to indicate the template type.
When to use useNewTemplate(position)?
Just apply the position that you need to use new template to useNewTemplate() and use it in your onItemClick() method.
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
useNewTemplate(position);
}
});
I have to replace the white image in the clicked position of GridView with green one to indicate its selected in onItemClickListener method. I have used custom adapter to preset the images in first look in my grid. What should i do to change the image of selected image only.
gridView.setAdapter(new CustomGridViewAdapter(ctx, R.layout.seatrow_grid, seat_list));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
String selectedItem;
Seat_Availabe st_av = (Seat_Availabe) arg0.getItemAtPosition(position);
if ((st_av.getAvailable().equals("true")) && (st_av.getLadiesSeat().equals("false"))) {
}
else{
Toast.makeText(getApplicationContext(), "Already Booked", Toast.LENGTH_LONG).show();
}
}
});
my adapter class to set images in first look
public class CustomGridViewAdapter extends ArrayAdapter<Seat_Availabe>
{
Context context;
int layoutResourceId;
List<Seat_Availabe> data = new ArrayList<Seat_Availabe>();
public CustomGridViewAdapter(Context context, int layoutResourceId, List<Seat_Availabe> data)
{
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
RecordHolder holder = null;
if (row == null)
{
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
row.setTag(holder);
}
else
{
holder = (RecordHolder) row.getTag();
}
Seat_Availabe seat = data.get(position);
String avail = seat.getAvailable();
String ladies = seat.getLadiesSeat();
if ((seat.getAvailable().equals("true")) && (seat.getLadiesSeat().equals("false"))) {
holder.imageItem.setImageResource(R.drawable.white);
}
else if((seat.getAvailable().equals("false")) && (seat.getLadiesSeat().equals("true")))
{
holder.imageItem.setImageResource(R.drawable.pink);
}
else if(seat.getAvailable().equals("false")){
holder.imageItem.setImageResource(R.drawable.gray);
}
else if(seat.getAvailable().equals("NA")){
holder.imageItem.setImageResource(R.drawable.whitenew);
}
else{
holder.imageItem.setImageResource(R.drawable.gray);
}
return row;
}
public static class RecordHolder
{
public ImageView imageItem;
}
}
I suppose you get the view object in the variable v of the click event, you could set the image of the view by:
v.setBackgroundResource(R.drawable.filename);//add your filename here
The current project I have includes a ListView with a Custom Adapter. However, I am now interested in adding multiple types of views to my ListView but after several attempts I have been unable to add the two sources of code together to successfully integrate them.
Article on ListView with multiple views: ListView Article for multiple views
The custom adapter in my current code retrieves the data from another class called getData which is referenced by "data".
Code from article (ListView with multiple views):
public class MultipleItemsList extends ListActivity {
private MyCustomAdapter mAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new MyCustomAdapter();
for (int i = 1; i < 50; i++) {
mAdapter.addItem("item " + i);
if (i % 4 == 0) {
mAdapter.addSeparatorItem("separator " + i);
}
}
setListAdapter(mAdapter);
}
private class MyCustomAdapter extends BaseAdapter {
private static final int TYPE_ITEM = 0;
private static final int TYPE_SEPARATOR = 1;
private static final int TYPE_MAX_COUNT = TYPE_SEPARATOR + 1;
private ArrayList mData = new ArrayList();
private LayoutInflater mInflater;
private TreeSet mSeparatorsSet = new TreeSet();
public MyCustomAdapter() {
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void addItem(final String item) {
mData.add(item);
notifyDataSetChanged();
}
public void addSeparatorItem(final String item) {
mData.add(item);
// save separator position
mSeparatorsSet.add(mData.size() - 1);
notifyDataSetChanged();
}
#Override
public int getItemViewType(int position) {
return mSeparatorsSet.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
#Override
public int getViewTypeCount() {
return TYPE_MAX_COUNT;
}
#Override
public int getCount() {
return mData.size();
}
#Override
public String getItem(int position) {
return mData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
System.out.println("getView " + position + " " + convertView + " type = " + type);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_ITEM:
convertView = mInflater.inflate(R.layout.item1, null);
holder.textView = (TextView)convertView.findViewById(R.id.text);
break;
case TYPE_SEPARATOR:
convertView = mInflater.inflate(R.layout.item2, null);
holder.textView = (TextView)convertView.findViewById(R.id.textSeparator);
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.textView.setText(mData.get(position));
return convertView;
}
}
public static class ViewHolder {
public TextView textView;
}
}
Current code (ListView with custom adapter):
FragmentA.java
package com.example.newsapp;
public class FragmentA extends Fragment{
getData data = getData.getMyData();
public Integer ArticleID;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View V = inflater.inflate(R.layout.fragment_a, container, false);
ListView listView = (ListView)V.findViewById(R.id.list)
CustomList adapter = new
CustomList(getActivity(), data.Headline.toArray(new String[data.Headline.size()]), data.Description.toArray(new String[data.Description.size()]), data.BitmapList.toArray(new Bitmap[data.BitmapList.size()]), data.ArticleID.toArray(new Integer[data.ArticleID.size()]));
listView.setAdapter(adapter);
listView.setOnItemClickListener(this); //Removed on click item event code.
return V;
}
CustomList.java
package com.example.newsapp;
public class CustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] titleId;
private final String[] descriptionId;
private final Bitmap[] pictureid;
public CustomList(Activity context,
String[] Headline, String[] Description, Bitmap[] BitmapList, Integer[] ArticleID) {
super(context, R.layout.single_row, Headline);
this.context = context;
this.titleId = Headline;
this.descriptionId = Description;
this.pictureid = BitmapList;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.single_row, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.tvTitle);
TextView txtDescription = (TextView) rowView.findViewById(R.id.tvDescription);
ImageView imageView = (ImageView) rowView.findViewById(R.id.ivIcon);
txtTitle.setText(titleId[position]);
txtDescription.setText(descriptionId[position]);
imageView.setImageBitmap(pictureid[position]);
return rowView;
}
}
Edit:
public class CustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] titleId;
private final String[] descriptionId;
private final Bitmap[] pictureid;
public CustomList(Activity context,
String[] Headline, String[] Description, Bitmap[] BitmapList, Integer[] ArticleID) {
super(context, R.layout.single_row, Headline);
this.context = context;
this.titleId = Headline;
this.descriptionId = Description;
this.pictureid = BitmapList;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
int viewType = getItemViewType(position);
View rowView = null;
switch(viewType) {
case 0:
LayoutInflater inflater = context.getLayoutInflater();
rowView= inflater.inflate(R.layout.single_row, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.tvTitle);
TextView txtDescription = (TextView) rowView.findViewById(R.id.tvDescription);
ImageView imageView = (ImageView) rowView.findViewById(R.id.ivIcon);
txtTitle.setText(titleId[position]);
txtDescription.setText(descriptionId[position]);
imageView.setImageBitmap(pictureid[position]);
case 1:
LayoutInflater inflater2 = context.getLayoutInflater();
rowView= inflater2.inflate(R.layout.single_row_loadmore, null, true);
}
return rowView;
}
#Override
public int getViewTypeCount() {
return 2; // TODO make this a static final
}
#Override
public int getItemViewType(int position) {
return position % 2; // 0 or 1
}
}
First, a bit of an aside: you should create a class that encapsulates a headline, description, etc. and use an array/collection of those objects to back your adapter. It will be far easier than managing many disparate arrays of things, especially if one day you decide you need another attribute of an Article (its category, for example).
class Article {
int id;
String headline;
String description;
Bitmap picture;
}
With regard to your ListView, the magic happens in the methods getItemViewType() and getViewTypeCount(). In getViewTypeCount() you return the maximum number of row types -- the article you posted uses two row types and so returns 2. In getItemViewType() you return a value between zero and (viewTypeCount - 1) -- in the article, his implementation can return 0 or 1 because his viewTypeCount is 2.
How you decide which row type applies to each item is entirely up to you. If, for example, you wanted to simply alternate view types on every row, you can do this:
#Override
public int getViewTypeCount() {
return 2; // TODO make this a static final
}
#Override
public int getItemViewType(int position) {
return position % 2; // 0 or 1
}
In other applications you would probably inspect the item at the given position to help you determine what should be returned in getItemViewtype().
The reason this functionality exists is that getView() provides a parameter (called convertView) that is a row which has been recycled. In order to give you an appropriate convertView, ListView needs to first know what row type it was. When you want to implement getView() for an adapter with multiple row types, it generally looks something like this:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
int viewType = getItemViewType(position);
switch(viewType) {
case 0:
return setUpOneViewType(position, convertView, parent);
case 1:
return setUpAnotherViewType(position, convertView, parent);
}
}
Note the cases for the switch statement correspond to the possible values that can be returned from getItemViewType(). These could be static final members.
I highly suggest watching The World of ListView. That video covers this topic as well as how to properly use convertView in your adapter implementation.