hello i want to ask make galleryview look like on android market.
this my code.
gridadapter
public class GridAdapter extends BaseAdapter {
int resource;
private ArrayList<GridModel> gm;
private Activity activity;
String response;
Context context;
public ImageLoader imageLoader;
public GridAdapter(Activity a, int resource, ArrayList<GridModel> gm)
{
this.gm = gm;
this.activity = a;
this.resource = resource;
this.imageLoader = new
ImageLoader(activity.getApplicationContext());
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return gm.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public GridModel getGridModel(int position) {
return gm.get(position);
}
public void setGridArray(ArrayList<GridModel> gm) {
this.gm = gm;
}
static class ViewHolder {
TextView name;
TextView jarak;
ImageView imgIcon;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
View v = convertView;
if(v==null){
LayoutInflater vi =
(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(resource, null);
holder = new ViewHolder();
holder.name = (TextView)v.findViewById(R.id.name);
holder.jarak = (TextView)v.findViewById(R.id.jarak);
holder.imgIcon =
(ImageView)v.findViewById(R.id.imgIcon);
v.setTag(holder);
}
else
holder = (ViewHolder)v.getTag();
GridModel gms = gm.get(position);
if(gm!=null){
holder.name.setText(gms.getName());
holder.jarak.setText(gms.getJarak());
try{
holder.imgIcon.setTag(gms.getImageUrl());
imageLoader.displayImage(gms.imageUrl,
activity, holder.imgIcon);
}catch (Exception e) {
// TODO: handle exception
}
}
return v;
}
void log(String text){
Log.e("GridAdapter", text);
}
}
gallery activity
public class Details extends Activity {
Bundle extras;
Gallery gallery1;
GridAdapter gridAdapter;
ArrayList<GridModel> listArray = null;
ImageLoader imgLoad;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
gallery1 = (Gallery) findViewById(R.id.gallery1);
listArray = new ArrayList<GridModel>();
gallery1.setAdapter(gridAdapter);
gallery1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2,
long arg3) {
// TODO Auto-generated method stub
}
});
extras = getIntent().getExtras();
try {
String response = extras.getString("json");
String judul = extras.getString("judul");
TextView txtJudul = (TextView) findViewById(R.id.judul);
txtJudul.setText(judul);
JSONObject json = new JSONObject(response);
JSONArray jArray = json.getJSONArray("provinsi");
Log.e("json", jArray.length() + "");
listArray = new ArrayList<GridModel>();
for (int i = 0; i < jArray.length(); i++) {
JSONObject jObject = jArray.getJSONObject(i);
JSONArray jSub =
jObject.getJSONArray("gallery");
if (!jObject.getString("name").equals(judul))
continue;
Log.e("jsongallery", jSub.length() + "");
for (int j = 0; j < jSub.length(); j++) {
JSONObject jGallery =
jSub.getJSONObject(j);
GridModel model = new GridModel();
model.setGalleryUrl(jGallery.getString("galleryUrl"));
listArray.add(model);
String galUrl =
extras.getString("gallery");
imgLoad = new ImageLoader(this);
Log.d("galurl", galUrl);
ImageView imgGallery = (ImageView)
findViewById(R.id.gallery1);
imgGallery.setTag(galUrl);
imgLoad.displayImage(galUrl, this,
imgGallery);
}
}
gridAdapter.setGridArray(listArray);
gridAdapter.notifyDataSetChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en