Created
June 6, 2011 09:13
-
-
Save rnaud/1009976 to your computer and use it in GitHub Desktop.
ListView with embed Gallery
This file contains hidden or 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 com.rnaud.karma; | |
import java.util.ArrayList; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.AdapterView; | |
import android.widget.AdapterView.OnItemClickListener; | |
import android.widget.BaseAdapter; | |
import android.widget.Gallery; | |
import android.widget.TextView; | |
public class MissionListAdapter2 extends BaseAdapter { | |
private LayoutInflater mInflater; | |
private Context context; | |
private static ArrayList<Mission> missions; | |
public MissionListAdapter2(Context c, ArrayList<Mission> m) { | |
mInflater = LayoutInflater.from(c); | |
context = c; | |
missions = m; | |
} | |
public int getCount() { | |
return missions.size(); | |
} | |
public Object getItem(int position) { | |
return missions.get(position); | |
} | |
public long getItemId(int position) { | |
return position; | |
} | |
public View getView(int position, View convertView, ViewGroup parent) { | |
ViewHolder holder; | |
if (convertView == null) { | |
convertView = mInflater.inflate(R.layout.missions_list_item, null); | |
holder = new ViewHolder(); | |
holder.text = (TextView) convertView.findViewById(R.id.TextView02); | |
holder.subtitle = (TextView) convertView.findViewById(R.id.subtitle); | |
holder.gallery = (Gallery) convertView.findViewById(R.id.gallery_mission); | |
convertView.setTag(holder); | |
} else { | |
holder = (ViewHolder) convertView.getTag(); | |
} | |
// Bind the data efficiently with the holder. | |
holder.m = missions.get(position); | |
holder.text.setText(holder.m.name); | |
holder.text.setTag(holder.m.id+""); | |
int mission_feats = holder.m.photos_count; | |
String status; | |
if (holder.m.wit == null) { | |
status = "you haven't done it"; | |
} else if (holder.m.wit.status == 0) { | |
status = "running mission"; | |
} else { | |
status = "mission done"; | |
} | |
holder.subtitle.setText(mission_feats+ " feats done, "+ status); | |
holder.gallery.setAdapter(new MissionGridAdapter2(context, holder.m.photos)); | |
holder.gallery.setSelection((int)( holder.m.photos.size()/2) ); | |
holder.gallery.setOnItemClickListener(new OnItemClickListener() { | |
public void onItemClick(AdapterView<?> parent, View v, int position, long id) { | |
long p_id = Long.valueOf(v.getTag().toString()); | |
Intent i = new Intent(context, PhotoPage.class); | |
i.putExtra(KarmaDbAdapter.PHOTO_ID, p_id); | |
context.startActivity(i); | |
} | |
}); | |
return convertView; | |
} | |
static class ViewHolder { | |
TextView text; | |
TextView subtitle; | |
Gallery gallery; | |
Mission m; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package com.rnaud.karma;
import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.TextView;
public class MissionListAdapter2 extends BaseAdapter {
private LayoutInflater mInflater;
private Context context;
private static ArrayList missions;
private static ArrayList missionsGridAdapters;