Main Adapter
public class NewTreatmentAdapter extends BaseAdapter {
Context mContext;
LayoutInflater inflater;
ArrayList<MyTreatmentDetailNew> list;
public NewTreatmentAdapter(Context context, ArrayList<MyTreatmentDetailNew> list) {
this.mContext = context;
this.list = list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
MyTreatmentDetailNew allergiesDetails = (MyTreatmentDetailNew) list.get(position);
Holders holders;
View view = convertView;
if (convertView == null) {
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.new_my_treat_list, parent, false);
holders = new Holders();
holders.txtFrom = (TextView) view.findViewById(R.id.txtFrom);
holders.txtTreatmnt = (TextView) view.findViewById(R.id.txtTreatmnt);
holders.txtStatus = (TextView) view.findViewById(R.id.txtStatus);
holders.lView = (ListView) view.findViewById(R.id.lView);
holders.txtFrom.setTag(list.get(position));
holders.txtTreatmnt.setTag(list.get(position));
holders.txtStatus.setTag(list.get(position));
holders.lView.setTag(list.get(position));
view.setTag(holders);
} else {
holders = (Holders) view.getTag();
((Holders) view.getTag()).txtFrom.setTag(list.get(position));
((Holders) view.getTag()).txtTreatmnt.setTag(list.get(position));
((Holders) view.getTag()).txtStatus.setTag(list.get(position));
((Holders) view.getTag()).lView.setTag(list.get(position));
}
holders.txtFrom.setText(allergiesDetails.fromName);
holders.txtTreatmnt.setText(allergiesDetails.treatmntName);
holders.txtStatus.setText(allergiesDetails.status);
ArrayList<MyTreatmentSubDetailNew> subDetailList = allergiesDetails.subDetailList;
if(subDetailList!=null && subDetailList.size()!=0) {
NewTreatmentSubAdapter subAdapter = new NewTreatmentSubAdapter(mContext, subDetailList);
holders.lView.setAdapter(subAdapter);
//((ViewGroup)convertView).addView(holders.lView);
//holders.lView.setTag(allergiesDetails);
}
return view;
}
public class Holders {
TextView txtFrom, txtTreatmnt, txtStatus, txtDay, txtMg, txtOften, txtName;
ListView lView;
} }
SubAdapter
public class NewTreatmentSubAdapter extends BaseAdapter {
Context mContext;
LayoutInflater inflater;
ArrayList<MyTreatmentSubDetailNew> list;
public NewTreatmentSubAdapter(Context context, ArrayList<MyTreatmentSubDetailNew> list) {
this.mContext = context;
this.list = list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
MyTreatmentSubDetailNew allergiesDetails = (MyTreatmentSubDetailNew) list.get(position);
System.out.println("sub position >> "+position);
Holders holders;
View view = convertView;
if (convertView == null) {
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// view = inflater.inflate(R.layout.new_my_treat_sub_list, parent, false);
view = inflater.inflate(R.layout.new_my_treat_sub_list, null);
holders = new Holders();
holders.txtDay = (TextView) view.findViewById(R.id.txtDay);
holders.txtMg = (TextView) view.findViewById(R.id.txtMg);
holders.txtOften = (TextView) view.findViewById(R.id.txtOften);
holders.txtName = (TextView) view.findViewById(R.id.txtName);
holders.txtDay.setTag(list.get(position));
holders.txtMg.setTag(list.get(position));
holders.txtOften.setTag(list.get(position));
holders.txtName.setTag(list.get(position));
view.setTag(holders);
} else {
holders = (Holders) view.getTag();
((Holders) view.getTag()).txtDay.setTag(list.get(position));
((Holders) view.getTag()).txtMg.setTag(list.get(position));
((Holders) view.getTag()).txtName.setTag(list.get(position));
((Holders) view.getTag()).txtOften.setTag(list.get(position));
}
holders.txtDay = (TextView) view.findViewById(R.id.txtDay);
holders.txtMg = (TextView) view.findViewById(R.id.txtMg);
holders.txtOften = (TextView) view.findViewById(R.id.txtOften);
holders.txtName = (TextView) view.findViewById(R.id.txtName);
holders.txtDay.setText("" + allergiesDetails.Days);
holders.txtMg.setText(allergiesDetails.Dosage);
holders.txtName.setText(allergiesDetails.MedicineName);
holders.txtOften.setText(allergiesDetails.AsNeed + "," + allergiesDetails.Morning + "," + allergiesDetails.AfterNoon + "," + allergiesDetails.Night);
// ((ViewHolder) view.getTag()).edittextComments.setTag(arrayListIndividualEvaluationSectionsService.get(position));
return view;
}
public class Holders {
TextView txtFrom, txtTreatmnt, txtStatus, txtDay, txtMg, txtOften, txtName;
ListView lView;
}
/*
public Object getItem(int position) {
for (Organization org : orgnizations) {
if (position == 0) {
return org;
}
position--;
List<Contact> contacts = org.getContacts();
if (contacts != null) {
int size = contacts.size();
if (position >= size) {
position -= size;
} else {
return contacts.get(position);
}
}
}*/
}
Related
when i was trying tutorial checkbox in listview theres some error on my adapter
public View getView(int position, View convertView, ViewGroup parent) {
ViewTag viewTag;
if (convertView == null) {
//取得listItem容器 view
convertView = myInflater.inflate(R.layout.list_item_pegawai, null);
//建構listItem內容view
viewTag = new ViewTag(
(TextView) convertView.findViewById(R.id.txt_namapegawai),
(CheckBox) convertView.findViewById(R.id.checkBox_pegawai));
//設置容器內容
convertView.setTag(viewTag);
} else {
viewTag = (ViewTag) convertView.getTag();
}
complete code
public class CustomAdapter extends BaseAdapter {
private Context context;
public static ArrayList<Model> modelArrayList;
public CustomAdapter(Context context, ArrayList<Model> modelArrayList) {
this.context = context;
CustomAdapter.modelArrayList = modelArrayList;
}
#Override
public int getViewTypeCount() {
return getCount();
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public int getCount() {
return modelArrayList.size();
}
#Override
public Object getItem(int position) {
return modelArrayList.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item_select, null, true);
holder.checkBox = convertView.findViewById(R.id.checkBox);
holder.tvName = convertView.findViewById(R.id.textView7);
holder.Tvnumber = convertView.findViewById(R.id.textView8);
convertView.setTag(holder);
} else {
// the getTag returns the viewHolder object set as a tag to the view
holder = (ViewHolder) convertView.getTag();
}
holder.tvName.setText(modelArrayList.get(position).getName());
holder.Tvnumber.setText(modelArrayList.get(position).getPhone());
holder.checkBox.setChecked(modelArrayList.get(position).getSelected());
holder.checkBox.setTag(R.integer.btnplusview, convertView);
holder.checkBox.setTag(position);
holder.checkBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview);
TextView tv = tempview.findViewById(R.id.textView7);
Integer pos = (Integer) holder.checkBox.getTag();
if (modelArrayList.get(pos).getSelected()) {
modelArrayList.get(pos).setSelected(false);
} else {
modelArrayList.get(pos).setSelected(true);
}
}
});
return convertView;
}
private class ViewHolder {
protected CheckBox checkBox;
private TextView tvName;
private TextView Tvnumber;
}
}
public class ListViewAdapter extends BaseAdapter {
private Context context;
private LocationDetails[] locationDetails;
public ListViewAdapter(Context c, LocationDetails[] locationDetails) {
context = c;
this.locationDetails = locationDetails;
}
#Override
public int getCount() {
return locationDetails.length;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
View list;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (view == null) {
list = new View(context);
list = inflater.inflate(R.layout.listview_layout, null);
TextView name = (TextView) list.findViewById(R.id.location_name);
TextView desc = (TextView) list.findViewById(R.id.location_desc);
ImageView img = (ImageView) list.findViewById(R.id.location_image);
name.setText(locationDetails[i].getLocationName());
desc.setText(locationDetails[i].getLocationDesc());
img.setImageResource(locationDetails[i].getLocationIcon());
} else {
list = (View) view;
}
return list;
}
}
This code is the code before I use viewholder, it works fine. Then I tried to modify it with the use of viewholder, and compile it with gradle, all the image and textviews disappeared, I don't know what's wrong with the code below. Why can't I get any thing shown on the screen?
public class LocationAdapter extends BaseAdapter {
private Context context;
private LocationDetails[] locationDetails;
public LocationAdapter(Context c, LocationDetails[] locationDetails) {
context = c;
this.locationDetails = locationDetails;
}
#Override
public int getCount() {
return locationDetails.length;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
View list = view;
ViewHolder vh;
if (list == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
list = inflater.inflate(R.layout.listview_layout, null);
vh = new ViewHolder();
vh.name = (TextView) list.findViewById(R.id.location_name);
vh.desc = (TextView) list.findViewById(R.id.location_desc);
vh.img = (ImageView) list.findViewById(R.id.location_image);
list.setTag(vh);
} else {
vh = (ViewHolder) list.getTag();
}
return list;
}
static class ViewHolder {
TextView name;
TextView desc;
ImageView img;
}
}
public class LocationAdapter extends BaseAdapter {
private Context context;
private LocationDetails[] locationDetails;
Object model;
public LocationAdapter(Context c, LocationDetails[] locationDetails) {
context = c;
this.locationDetails = locationDetails;
}
#Override
public int getCount() {
return locationDetails.length;
}
#Override
public Object getItem(int i) {
return i;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
View list = view;
ViewHolder vh;
if (list == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
list = inflater.inflate(R.layout.listview_layout, null);
vh = new ViewHolder();
vh.name = (TextView) list.findViewById(R.id.location_name);
vh.desc = (TextView) list.findViewById(R.id.location_desc);
vh.img = (ImageView) list.findViewById(R.id.location_image);
list.setTag(vh);
} else {
vh = (ViewHolder) list.getTag();
}
model = getItem(i);
vh.name.setText(model.getLocationName());
vh.desc.setText(model.getLocationDesc());
// same as image...
return list;
}
static class ViewHolder {
TextView name;
TextView desc;
ImageView img;
}
}
I have GridView which contain the number of items, If user click on save button then selected value show in ListView, I tried but not got succeied, Can any one help to solve this problem?
MainActivity.java
fillDataMyProperty();
if (myPropertyArrayList != null && myPropertyArrayList.size() > 0) {
myPropertListAdapter = new MyPropertListAdapter(MainActivity.this, myPropertyArrayList, txtSubmit);
gridMyProperty.setAdapter(myPropertListAdapter);
}
My GridAdapter is
public class MyPropertListAdapter extends BaseAdapter {
private Context context;
private ArrayList<ItemModel> arrayList;
private boolean check = false;
private View view;
private TextView txtSubmit;
public MyPropertListAdapter(Context context, ArrayList<ItemModel> arrayList, TextView txtSubmit) {
this.context = context;
this.arrayList = arrayList;
this.txtSubmit = txtSubmit;
}
#Override
public int getCount() {
return arrayList.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public int getViewTypeCount() {
return super.getViewTypeCount();
}
#SuppressLint("InflateParams")
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewHolder viewHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_item_row, null);
viewHolder = new ViewHolder();
viewHolder.txtItem = (TextView) convertView.findViewById(R.id.txtItem);
viewHolder.rlMain = (RelativeLayout) convertView.findViewById(R.id.rlMain);
viewHolder.imgCheck = (ImageView) convertView.findViewById(R.id.imgCheck);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.txtItem.setText(arrayList.get(position).getItem_name());
if (arrayList.get(position).isCheck() == true) {
viewHolder.txtItem.setBackgroundResource(R.drawable.ic_green_facility);
Glide.with(context).load(R.drawable.ic_facility_check).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).dontAnimate().into(viewHolder.imgCheck);
} else if (arrayList.get(position).isCheck() == false) {
viewHolder.txtItem.setBackgroundResource(R.drawable.ic_white_facility);
viewHolder.imgCheck.setVisibility(View.GONE);
}
viewHolder.rlMain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
view = v;
if (arrayList.get(position).isCheck() == false) {
Log.d("if---------------------", String.valueOf(arrayList.get(position).isCheck()));
viewHolder.txtItem.setBackgroundResource(R.drawable.ic_green_facility);
viewHolder.imgCheck.setVisibility(View.VISIBLE);
Glide.with(context).load(R.drawable.ic_facility_check).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).dontAnimate().into(viewHolder.imgCheck);
arrayList.get(position).setCheck(true);
check = true;
} else if (arrayList.get(position).isCheck() == true) {
Log.d("else-------------------", String.valueOf(arrayList.get(position).isCheck()));
viewHolder.txtItem.setBackgroundResource(R.drawable.ic_white_facility);
viewHolder.imgCheck.setVisibility(View.GONE);
arrayList.get(position).setCheck(false);
check = false;
}
}
});
txtSubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showItemsDilaog();
}
});
return convertView;
}
public class ViewHolder {
TextView txtItem;
RelativeLayout rlMain;
ImageView imgCheck;
}
private void showItemsDilaog() {
final Dialog mDialog = new Dialog(context);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
mDialog.setContentView(R.layout.dialog_list_item);
ImageView imgCancel = (ImageView) mDialog.findViewById(R.id.imgCancel);
ListView listItem = (ListView) mDialog.findViewById(R.id.listItem);
if (arrayList != null && arrayList.size() > 0) {
ItemsAdapter mAdapter = new ItemsAdapter(context, arrayList);
listItem.setAdapter(mAdapter);
}
imgCancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDialog.dismiss();
}
});
mDialog.show();
}}
ItemsAdapter.Java
class ItemsAdapter extends BaseAdapter {
// private String[] mStrings = new String[]{"Elevator", "Air Conditionor", "Electricity", "Houe Keeping", "Garden", "All"};
private ViewHolder viewHolder;
private Context context;
private ArrayList<ItemModel> mArrayList;
public ItemsAdapter(Context context, ArrayList<ItemModel> maintananceModelArrayList) {
this.context = context;
this.mArrayList = maintananceModelArrayList;
}
#Override
public int getCount() {
return mArrayList.size();
}
#Override
public Object getItem(int position) {
return mArrayList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_row, null);
viewHolder = new ViewHolder();
viewHolder.txtItem = (TextView) convertView.findViewById(R.id.txtItem);
viewHolder.lineSeperator = (View) convertView.findViewById(R.id.lineSeperator);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if (arrayList.get(position).isCheck() == true) {
viewHolder.txtItem.setText(arrayList.get(position).getItem_name());
Log.d("Items:::::::::::::::",arrayList.get(position).getItem_name());
}
if (position == arrayList.size() - 1) {
viewHolder.lineSeperator.setVisibility(View.GONE);
} else {
viewHolder.lineSeperator.setVisibility(View.VISIBLE);
}
return convertView;
}
public class ViewHolder {
TextView txtItem;
View lineSeperator;
}
}
Senario: To get rating feedback for multiple multiple products.
Problem: Ratingbar value resets on scrolling listview by calling setOnRatingBarChangeListener
Expected output:
Customized listview adpater code:
public class FeedbackAdapter extends BaseAdapter {
static Context context;
List<FeedbackRowDetails> row;
ViewHolder holder;
public FeedbackAdapter(Context context,List<FeedbackRowDetails> row)
{
this.context = context;
this.row =row;
}
private class ViewHolder {
TextView tv_slno, tv_productname, tv_time;
RatingBar rb_productrating;
}
#Override
public View getView( final int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.custom_feedback_row_format,null);
holder = new ViewHolder();
holder.tv_slno = (TextView) convertView.findViewById(R.id.tv_slno);
holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
holder.tv_productname = (TextView) convertView.findViewById(R.id.tv_productname);
holder.rb_productrating=(RatingBar) convertView.findViewById(R.id.rb_productrating);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
FeedbackRowDetails row_pos = row.get(position);
holder.tv_slno.setText(String.valueOf(position + 1));
holder.tv_time.setText(row_pos.gettime());
holder.tv_productname.setText(row_pos.getproductsName());
holder.rb_productrating.setRating(Float.valueOf(row_pos.getrating()));
holder.rb_productrating.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
public void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser)
{
FeedbackRowDetails row_pos = row.get(position);
int roundoff_rating = (int)Math.round(rating);
ratingBar.setRating(roundoff_rating);
row_pos.setrating(String.valueOf(roundoff_rating));
}
});
return convertView;
}
#Override
public int getCount() {
return row.size();
}
#Override
public Object getItem(int position) {
return row.get(position);
}
#Override
public long getItemId(int position) {
return row.indexOf(getItem(position));
}
}
Just wrap your codes present inside your onRatingChanged method with a simple if as shown below
if(fromUser) {
FeedbackRowDetails row_pos = row.get(position);
int roundoff_rating = (int) Math.round(rating);
ratingBar.setRating(roundoff_rating);
row_pos.setRating(String.valueOf(roundoff_rating));
}
Have tested it with emulator and it was working as expected. Hope this solves your problem
This problem solved with reference to link
public class FeedbackAdapter extends BaseAdapter {
static Context context;
List<FeedbackRowDetails> row;
ViewHolder holder;
public FeedbackAdapter(Context context,List<FeedbackRowDetails> row)
{
this.context = context;
this.row =row;
}
private class ViewHolder {
TextView tv_slno, tv_productname, tv_time;
RatingBar rb_productrating;
}
#Override
public View getView( final int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.custom_feedback_row_format,parent, false);
holder = new ViewHolder();
holder.tv_slno = (TextView) convertView.findViewById(R.id.tv_slno);
holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
holder.tv_productname = (TextView) convertView.findViewById(R.id.tv_productname);
holder.rb_productrating=(RatingBar) convertView.findViewById(R.id.rb_productrating);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
holder.rb_productrating.setOnRatingBarChangeListener(onRatingChangedListener(holder, position));
holder.rb_productrating.setTag(position);
holder.tv_slno.setText(String.valueOf(position + 1));
holder.tv_time.setText(getItem(position).gettime());
holder.tv_productname.setText(getItem(position).getproductsName());
float rating=Float.valueOf(getItem(position).getrating());
holder.rb_productrating.setRating(rating);
return convertView;
}
private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final ViewHolder holder, final int position)
{
return new RatingBar.OnRatingBarChangeListener() {
#Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean b)
{
FeedbackRowDetails item = row.get(position);
int roundoff_rating = (int)Math.round(rating);
ratingBar.setRating(roundoff_rating);
item.setrating(String.valueOf(roundoff_rating));
}
};
}
#Override
public int getCount() {
return row.size();
}
#Override
public FeedbackRowDetails getItem(int position)
{
return row.get(position);
}
#Override
public long getItemId(int position) {
return row.indexOf(getItem(position));
}
}
I have a listView (vertical) and every list item has a horizontal list view (horizontal).
But the problem is when i scroll the horizontal scrollview in the row the vertical list is also calling getView()...
So, there is a huge performance hit..
So , can any one tell me a better solution to it ..
public class GridViewAdapter extends BaseAdapter {
List<List<Hotel>> gridDatasource;
Context mContext;
public GridViewAdapter(List<List<Hotel>> gridDatasource, Context context) {
this.gridDatasource = gridDatasource;
this.mContext = context;
}
public void setGridDatasource(List<List<Hotel>> gridDatasource) {
this.gridDatasource = gridDatasource;
}
#Override
public int getCount() {
if (gridDatasource == null) {
return 0;
}
return gridDatasource.size();
}
#Override
public Object getItem(int position) {
return gridDatasource.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
GridViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.gridview_table_cell,
null);
holder = new GridViewHolder();
holder.headerView = (TextView) convertView
.findViewById(R.id.gridViewRowHeader);
holder.listView = (HorizontalListView) convertView
.findViewById(R.id.gridViewHorizontalListView);
convertView.setTag(holder);
} else {
holder = (GridViewHolder) convertView.getTag();
Log.d("TAG", "Reaching Here");
}
holder.headerView.setText("Hello From Sandeep");
HorizontalListViewAdapter adapter = new HorizontalListViewAdapter(
mContext, gridDatasource.get(position));
holder.listView.setAdapter(adapter);
return convertView;
}
}
static class GridViewHolder {
TextView headerView;
HorizontalListView listView;
}
public class HorizontalListViewAdapter extends BaseAdapter {
Context mContext;
List<Hotel> mHotels;
public HorizontalListViewAdapter(Context context, List<Hotel> hotels) {
this.mContext = context;
this.mHotels = hotels;
}
#Override
public int getCount() {
if (mHotels == null) {
return 0;
}
return mHotels.size();
}
#Override
public Object getItem(int position) {
return mHotels.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
HotelCell cell = (HotelCell) convertView;
if (cell == null) {
cell = new HotelCell(mContext);
} else {
Log.d("TAG", "Reached here 2");
}
cell.setHotel(mHotels.get(position));
cell.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(mContext,
HotelDetailActivity.class);
intent.putExtra("DATA", ((HotelCell) v).getHotel());
startActivity(intent);
}
});
cell.setPadding(0, 0, 10, 0);
return cell;
}
}
Dear i suggest to try My this Code
public View getView(final int position, View convertView, ViewGroup parent)
{
View v = convertView;
ViewHolder holder;
if (v == null)
{
v = inflater.inflate(R.layout.custom_image_layout, null);
holder = new ViewHolder();
holder.txtFileName = (TextView) v.findViewById(R.id.txtFileName);
holder.imageView = (ImageView) v.findViewById(R.id.imgView);
v.setTag(holder);
} else
{
holder = (ViewHolder) v.getTag();
}
holder.imageView.setImageBitmap(bm);
holder.txtFileName.setText(""+nameoffile);
return v;
}
static class ViewHolder
{
public ImageView imageView;
public TextView txtFileName;
}
Use The Holder Class