Skip to content

Instantly share code, notes, and snippets.

@jophde
Created November 9, 2011 22:46
Show Gist options
  • Save jophde/1353410 to your computer and use it in GitHub Desktop.
Save jophde/1353410 to your computer and use it in GitHub Desktop.
ListView Adapter
private class VenuesAdapter extends BaseAdapter implements ListAdapter {
private final JSONArray venues;
private VenuesAdapter(JSONArray venues) {
assert venues != null;
this.venues = venues;
}
@Override
public int getCount() {
return venues.length();
}
@Override
public JSONObject getItem(int position) {
return venues.optJSONObject(position);
}
@Override
public long getItemId(int position) {
JSONObject venue = getItem(position);
return venue.optLong("idVenue");
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = Venues.this.getLayoutInflater().inflate(R.layout.venues_row, null);
JSONObject venue = getItem(position);
int venueStatus = venue.optInt("iStatus");
String sName = venue.optString("sName");
String sAddress = venue.optString("sStreet") + " " + venue.optString("sCity") + ", " + venue.optString("sState");
String sImageUrl = venue.optString("sImageUrl-thumb");
long idVenue = venue.optInt("idVenue");
ImageView venuesRowImage = (ImageView) convertView.findViewById(R.id.venues_row_image);
ImageView venuesRowStatus = (ImageView) convertView.findViewById(R.id.venues_row_status);
TextView venuesRowName = (TextView) convertView.findViewById(R.id.venues_row_name);
TextView venuesRowAddress = (TextView) convertView.findViewById(R.id.venues_row_address);
if (Venues.this.idVenue == idVenue)
convertView.setSelected(true);
Venues.this.new DownloadImageTask(venuesRowImage, sImageUrl).execute();
switch (venueStatus) {
case 1:
venuesRowStatus.setImageResource(R.drawable.venue_status_online);
break;
case 3:
venuesRowImage.setAlpha(120);
venuesRowStatus.setImageResource(R.drawable.venue_status_offline);
break;
}
venuesRowStatus.setAlpha(230);
venuesRowName.setText(sName);
venuesRowAddress.setText(sAddress);
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment