Skip to content

Instantly share code, notes, and snippets.

@sankarganesh
Created April 2, 2012 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sankarganesh/2285701 to your computer and use it in GitHub Desktop.
Save sankarganesh/2285701 to your computer and use it in GitHub Desktop.
Base Adpater
class MyGridAdapter extends BaseAdapter{
int temp_position=0,temp_count=0;
public int getCount() {
// TODO Auto-generated method stub
return page_no.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
try {
if (convertView == null)
convertView = View.inflate(AllPage.this,
R.layout.grid_icon, null);
temp_count = AllPage.p_chap_value;
if (temp_count != 0) {
if ((position == 0)) {
((ImageView) convertView.findViewById(R.id.imagepart))
.setImageDrawable(Util.getDrawable(urlvalue
.get(position) + "thump.jpg"));
temp_position = position+1;
((ImageView) convertView
.findViewById(R.id.imagepart_single))
.setVisibility(View.VISIBLE);
((ImageView) convertView
.findViewById(R.id.imagepart_single))
.setImageDrawable(Util.getDrawable(urlvalue
.get(temp_position) + "thump.jpg"));
temp_position=temp_position+1;
}else{
((ImageView) convertView.findViewById(R.id.imagepart))
.setImageDrawable(Util.getDrawable(urlvalue
.get(temp_position) + "thump.jpg"));
temp_position=temp_position+1;
((ImageView) convertView
.findViewById(R.id.imagepart_single))
.setImageDrawable(Util.getDrawable(urlvalue
.get(temp_position) + "thump.jpg"));
temp_position+=1;
}
} else {
temp_position=position;
if ((position == 0)) {
((ImageView) convertView.findViewById(R.id.imagepart))
.setImageDrawable(Util.getDrawable(urlvalue
.get(position) + "thump.jpg"));
((ImageView) convertView
.findViewById(R.id.imagepart_single))
.setVisibility(View.INVISIBLE);
} else {
((ImageView) convertView.findViewById(R.id.imagepart))
.setImageDrawable(Util.getDrawable(urlvalue
.get(temp_position) + "thump.jpg"));
((ImageView) convertView
.findViewById(R.id.imagepart_single))
.setImageDrawable(Util.getDrawable(urlvalue
.get(temp_position+1) + "thump.jpg"));
}
}
((TextView) convertView.findViewById(R.id.ItemText))
.setText(Html.fromHtml(title_vlaues.get(position)
+ "<br/>" + page_no.get(position)));
// ((ImageView)
// convertView.findViewById(R.id.imagepart)).setImageResource(R.drawable.icon);
((ImageView) convertView.findViewById(R.id.imagepart)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Util.error("Pos"+v.getId());
Util.error("temp pos"+temp_position);
}
});
((ImageView) convertView.findViewById(R.id.imagepart_single)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Util.error("Positon"+v.getId());
Util.error("temp pos"+temp_position);
}
});
} catch (Exception e) {
// TODO: handle exception
}
return convertView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment