Created
November 23, 2013 07:42
-
-
Save pratamawijaya/7611941 to your computer and use it in GitHub Desktop.
contoh adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package id.pratama.kulinerjogja; | |
import java.util.List; | |
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; | |
public class LokasiAdapte extends BaseAdapter | |
{ | |
static class ViewHolder | |
{ | |
TextView title, alamat; | |
ImageView thumb; | |
} | |
private Context context; | |
private LayoutInflater inflater; | |
private List<Lokasi> listLokasi; | |
public LokasiAdapte(Context con, List<Lokasi> listLokasi) | |
{ | |
this.context = con; | |
this.listLokasi = listLokasi; | |
inflater = LayoutInflater.from(context); | |
} | |
@Override | |
public int getCount() | |
{ | |
// TODO Auto-generated method stub | |
return listLokasi.size(); | |
} | |
@Override | |
public Object getItem(int position) | |
{ | |
// TODO Auto-generated method stub | |
return listLokasi.get(position); | |
} | |
@Override | |
public long getItemId(int position) | |
{ | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) | |
{ | |
// TODO Auto-generated method stub | |
ViewHolder holder; | |
if (convertView == null) | |
{ | |
convertView = inflater.inflate(R.layout.single_row, null); | |
holder = new ViewHolder(); | |
holder.title = (TextView) convertView.findViewById(R.id.txt_tempat); | |
holder.alamat = (TextView) convertView | |
.findViewById(R.id.txt_alamat); | |
holder.thumb = (ImageView) convertView.findViewById(R.id.thumb); | |
convertView.setTag(holder); | |
} else | |
{ | |
holder = (ViewHolder) convertView.getTag(); | |
} | |
holder.title.setText(listLokasi.get(position).getNama()); | |
holder.alamat.setText(listLokasi.get(position).getAlamat()); | |
holder.thumb.setImageResource(listLokasi.get(position).getGambar()); | |
return convertView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment