I have arraylist.Size of arraylist is 156.when I am running for loop it's running 156 times and it's adding all values into another arraylist.But when I am setting this arraylist into adapter adapter taking 156 items but when I am setting adapter into listview that time Listview taking only 98 items only.
When I am debugging I seen arralist size 156.and arraylist deviding into sets like
0-99
100-199
200-210
see below image :
Here my adapter taking only 0-99 items.How I can add 100-199 set Items into Listview.
Edit #1:
Adapter class :
public class AllserversListAdapter extends BaseAdapter implements OnClickListener {
Activity mActivity;
ArrayList<AllServers> mAllServersArray;
private static LayoutInflater mInflater = null;
ArrayList<MyFavorites> mFavoriteServers;
public AllserversListAdapter(Activity activity,
ArrayList<AllServers> allServers,
ArrayList<MyFavorites> favoriteServers) {
// TODO Auto-generated constructor stub
mActivity = activity;
mAllServersArray = allServers;
mFavoriteServers = favoriteServers;
mInflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return mAllServersArray.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;
}
ViewHolder holder;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (vi == null) {
/****** Inflate list items layout file for each row ( Defined below ) *******/
vi = mInflater.inflate(R.layout.servers_list_items, null);
/****** View Holder Object to contain list items file elements ******/
holder = new ViewHolder();
holder.serverName = (TextView) vi
.findViewById(R.id.server_items_country_name_textview);
holder.speed = (TextView) vi
.findViewById(R.id.server_items_speed_textview);
holder.speedTitleTextView = (TextView) vi
.findViewById(R.id.speed_title_textview);
holder.flag = (ImageView) vi.findViewById(R.id.server_flag_image);
holder.star = (ImageView) vi.findViewById(R.id.server_items_star);
holder.bodyLayout = (LinearLayout) vi
.findViewById(R.id.servere_items_boady_layout);
holder.speedBackgroundLayout = (LinearLayout) vi
.findViewById(R.id.speed_backround_layout);
holder.itemsParentLayout = (LinearLayout) vi
.findViewById(R.id.server_list_items_parentlayout);
holder.itemsParentLayout.setBackgroundColor(mActivity
.getResources().getColor(R.color.light_gray));
holder.bodyLayout.setBackgroundColor(mActivity.getResources()
.getColor(R.color.dark_gray_black));
holder.star.setOnClickListener(this);
/************ Set holder with LayoutInflater ************/
vi.setTag(holder);
holder.star.setTag(position);
holder.flag.setTag(position);
} else {
holder = (ViewHolder) vi.getTag();
}
String ip = mAllServersArray.get(position).getIp();
String country = mAllServersArray.get(position).getCountry();
String region = mAllServersArray.get(position).getRegion();
String speed = mAllServersArray.get(position).getSpeed();
String flagCountryCode = mAllServersArray.get(position)
.getCountrycode();
int ipSpeed = Integer.valueOf(speed);
holder.speedTitleTextView.setVisibility(View.GONE);
holder.speed.setText("TimeOut");
holder.speed.setTypeface(Typeface.DEFAULT);
holder.speed.setPadding(26, 0, 26, 0);
holder.speedBackgroundLayout.setBackgroundColor(mActivity
.getResources().getColor(R.color.time_out_color));
holder.serverName.setText(country + "\n" + region + "\n" + ip);
return vi;
}
}
Adding items into arraylist :
Any one give me suggest.
Try this way,hope this will help you to solve your problem.
public class AllserversListAdapter extends BaseAdapter{
Context context;
ArrayList<AllServers> allServers;
ArrayList<MyFavorites> favoriteServers;
public AllserversListAdapter(Context context,ArrayList<AllServers> allServers,ArrayList<MyFavorites> favoriteServers) {
this.context = context;
this.allServers = allServers;
this.favoriteServers = favoriteServers;
}
#Override
public int getCount() {
return mAllServersArray.size();
}
#Override
public Object getItem(int position) {
return mAllServersArray.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.servers_list_items, null);
holder.serverName = (TextView) convertView.findViewById(R.id.server_items_country_name_textview);
holder.speed = (TextView) convertView.findViewById(R.id.server_items_speed_textview);
holder.speedTitleTextView = (TextView) convertView.findViewById(R.id.speed_title_textview);
holder.flag = (ImageView) convertView.findViewById(R.id.server_flag_image);
holder.star = (ImageView) convertView.findViewById(R.id.server_items_star);
holder.bodyLayout = (LinearLayout) convertView.findViewById(R.id.servere_items_boady_layout);
holder.speedBackgroundLayout = (LinearLayout) convertView.findViewById(R.id.speed_backround_layout);
holder.itemsParentLayout = (LinearLayout) convertView.findViewById(R.id.server_list_items_parentlayout);
holder.itemsParentLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.light_gray));
holder.bodyLayout.setBackgroundColor(mActivity.getResources().getColor(R.color.dark_gray_black));
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String ip = mAllServersArray.get(position).getIp();
holder.speedTitleTextView.setVisibility(View.GONE);
holder.speed.setText("TimeOut");
holder.speed.setTypeface(Typeface.DEFAULT);
holder.speed.setPadding(26, 0, 26, 0);
holder.speedBackgroundLayout.setBackgroundColor(mActivity
.getResources().getColor(R.color.time_out_color));
holder.serverName.setText(mAllServersArray.get(position).getCountry() + "\n" + mAllServersArray.get(position).getRegion() + "\n" + ip);
holder.flag.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// try use (position) value to check which list item click.
}
});
holder.star.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// try use (position) value to check which list item click.
}
});
return convertView;
}
class ViewHolder {
TextView serverName;
TextView speed;
TextView speedTitleTextView;
ImageView flag;
ImageView star;
LinearLayout bodyLayout;
LinearLayout speedBackgroundLayout;
LinearLayout itemsParentLayout;
}
}
Related
What is want is to update total number in textview in one activity. i have a custom adapter which calls Arraylist in this activity then populates in listview, this adapter also has image view which removes the list item and does notifydatasetchanged().
this is my customadapter
private ArrayList<DataModel> dataSet;
Context mContext;
private static class ViewHolder {
TextView txtName;
TextView txtType;
Button remove;
}
public CustomAdapterForData(ArrayList<DataModel> data, Context context) {
super(context, R.layout.fields, data);
this.dataSet = data;
this.mContext=context;
}
#Override
public void onClick(View view) {
int position = (Integer) view.getTag();
Object object = getItem(position);
DataModel dataModel = (DataModel) object;
switch (view.getId())
{
case R.id.btnRemove:
remove(dataModel);
// dataSet.remove(position);
//dataSet.remove(position);
notifyDataSetChanged();
break;
}
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
DataModel dataModel = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
ViewHolder viewHolder; // view lookup cache stored in tag
final View result;
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.fields, parent, false);
viewHolder.txtName = (TextView) convertView.findViewById(R.id.fieldName);
viewHolder.txtType = (TextView) convertView.findViewById(R.id.tvPrize);
viewHolder.remove = (Button) convertView.findViewById(R.id.btnRemove);
result=convertView;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
result=convertView;
}
viewHolder.txtName.setText(dataModel.getFieldName());
viewHolder.txtType.setText(dataModel.getType());
viewHolder.remove.setOnClickListener(this);
viewHolder.remove.setTag(position);
return convertView;
}
after that this is my onstart()
protected void onStart() {
//if ((dataModels.size()!=0)){
ListView listView = (ListView) findViewById(R.id.listView);
adapter = new CustomAdapterForData(dataModels, getApplicationContext());
listView.setAdapter(adapter);
dataModelsnew = dataModels;
TextView tv = (TextView) findViewById(R.id.textViewTotal);
double sum = 0;
for (int i = 0 ; i < dataModelsnew.size(); i++){
sum = sum + dataModelsnew.get(i).getPrize();
}
tv.setText("Total : " + String.valueOf(Math.round(sum)*100d/100d));
//}
super.onStart();
}
what i want is populate latest value in textview which is sum of double (one element of ArrayList).Please help me to resolve this.
Thanks in advance. The variable i want to update after i remove something from list view otherwise it is working fine.
You can use DataSetObservers to detect any changes in your data:
final TextView tv = (TextView) findViewById(R.id.textViewTotal);
adapter.registerDataSetObserver(new DataSetObserver() {
#Override
public void onChanged() {
super.onChanged();
double sum = 0;
for (int i = 0 ; i < dataModels.size(); i++){
sum = sum + dataModels.get(i).getPrize();
}
tv.setText("Total : " + String.valueOf(Math.round(sum)*100d/100d));
}
});
I am trying to create something like this: https://i.stack.imgur.com/l8ZOc.png
However, i ran into a problem. When i create the list with my adapter, it is supposed to be a list of 8 items. However, it just shows the first 4 of these items in a random order two times. Do you see what is wrong with my code?
public class MyActivity extends Activity{
String headers[];
String image_urls[];
List<MyMenuItem> menuItems;
ListView mylistview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
menuItems = new ArrayList<MyMenuItem>();
headers = getResources().getStringArray(R.array.header_names);
image_urls = getResources().getStringArray(R.array.image_urls);
for (int i = 0; i < headers.length; i++) {
MyMenuItem item = new MyMenuItem(headers[i], image_urls[i]);
menuItems.add(item);
}
mylistview = (ListView) findViewById(R.id.list);
MenuAdapter adapter = new MenuAdapter(this, menuItems);
mylistview.setAdapter(adapter);
mylistview.setOnItemClickListener(this);
}
public class MyMenuItem {
private String item_header;
private String item_image_url;
public MyMenuItem(String item_header, String item_image_url){
this.item_header=item_header;
this.item_image_url=item_image_url;
}
public String getItem_header(){
return item_header;
}
public void setItem_header(String item_header){
this.item_header=item_header;
}
public String getItem_image_url(){
return item_image_url;
}
public void setItem_image_url(String item_image_url){
this.item_image_url=item_image_url;
}
}
public class MenuAdapter extends BaseAdapter{
Context context;
List<MyMenuItem> menuItems;
MenuAdapter(Context context, List<MyMenuItem> rowItems) {
this.context = context;
this.menuItems = rowItems;
}
#Override
public int getCount() {
return menuItems.size();
}
#Override
public Object getItem(int position) {
return menuItems.get(position);
}
#Override
public long getItemId(int position) {
return menuItems.indexOf(getItem(position));
}
private class ViewHolder {
ImageView ivMenu;
TextView tvMenuHeader;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.menu_item, null);
holder = new ViewHolder();
holder.tvMenuHeader = (TextView) convertView.findViewById(R.id.tvMenuHeader);
holder.ivMenu = (ImageView) convertView.findViewById(R.id.ivMenuItem);
MyMenuItem row_pos = menuItems.get(position);
Picasso.with(context)
.load(row_pos.getItem_image_url())
.placeholder(R.drawable.empty)
.error(R.drawable.error)
.into(holder.ivMenu);
holder.tvMenuHeader.setText(row_pos.getItem_header());
Log.e("Test", "headers:" + row_pos.getItem_header());
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
}
You are setting the data only when the convertView is null.So when it is not null,list items are inflated with data of previous list items. getView should be something like this
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.menu_item, null);
holder = new ViewHolder();
holder.tvMenuHeader = (TextView) convertView.findViewById(R.id.tvMenuHeader);
holder.ivMenu = (ImageView) convertView.findViewById(R.id.ivMenuItem);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
MyMenuItem row_pos = menuItems.get(position);
Picasso.with(context)
.load(row_pos.getItem_image_url())
.placeholder(R.drawable.empty)
.error(R.drawable.error)
.into(holder.ivMenu);
holder.tvMenuHeader.setText(row_pos.getItem_header());
Log.e("Test", "headers:" + row_pos.getItem_header());
return convertView;
}
I think this is the solution
else {
holder = (ViewHolder) convertView.getTag();
holder.tvMenuHeader.setText(row_pos.getItem_header());
}
I also encountered this problem earlier and this one works for me.
In my display adapter ptrelevant I visualize data from a database. I wish the M value of the column relative to the TextView turn, was colored red. How can I do this?
public DisplayAdapter(Context c, ArrayList<String> id,ArrayList<String> ore,ArrayList<String> turno) {
this.mContext = c;
this.id = id;
this.turnoName = turno;
this.oreName = ore;
}
public int getCount() {
// TODO Auto-generated method stub
return id.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int pos, View child, ViewGroup parent) {
Holder mHolder;
LayoutInflater layoutInflater;
if (child == null) {
layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutInflater.inflate(R.layout.row, null);
mHolder = new Holder();
mHolder.txt_turno = (TextView) child.findViewById(R.id.txt_turno);
mHolder.txt_ore = (TextView) child.findViewById(R.id.txt_ore);
mHolder.txt_id = (TextView) child.findViewById(R.id.txt_id);
child.setTag(mHolder);
} else {
mHolder = (Holder) child.getTag();
}
mHolder.txt_turno.setText(turnoName.get(pos));
mHolder.txt_ore.setText(oreName.get(pos));
return child;
}
public class Holder {
TextView txt_turno;
TextView txt_ore;
TextView txt_id;
}
}
Weird...that works for me:
try this :
mHolder.txt_turno.setText(turnoName.get(pos));
mHolder.txt_ore.setText(oreName.get(pos));
mHolder.txt_id.setText(dataName.get(pos));
String Turno = turnoName.get(pos);
mHolder.txt_turno.setTextColor(Color.WHITE);
if (Turno != null){
if (TextUtils.equals(Turno,"M"))
mHolder.txt_turno.setTextColor(Color.RED);
if (TextUtils.equals(Turno,"F"))
mHolder.txt_turno.setTextColor(Color.YELLOW);
}
return child;
}
hope that help you
Try adding the text in HTML format. Im pretty sure this will change the color. Your code should look like:
public View getView(int pos, View child, ViewGroup parent) {
Holder mHolder;
LayoutInflater layoutInflater;
if (child == null) {
layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutInflater.inflate(R.layout.row, null);
mHolder = new Holder();
mHolder.txt_turno = (TextView) child.findViewById(R.id.txt_turno);
mHolder.txt_ore = (TextView) child.findViewById(R.id.txt_ore);
mHolder.txt_id = (TextView) child.findViewById(R.id.txt_id);
child.setTag(mHolder);
} else {
mHolder = (Holder) child.getTag();
}
if (turnoName.get(pos).toString().equalsIgnoreCase("M")){
mHolder.txt_turno.setText(Html.fromHtml("<font color='#FF0000'>"+turnoName.get(pos)+"</font>"));
}else if(turnoName.get(pos).toString().equalsIgnoreCase("F")){
mHolder.txt_turno.setText(Html.fromHtml("<font color='#FFFF00'>"+turnoName.get(pos)+"</font>"));
}else{
mHolder.txt_turno.setText(Html.fromHtml("<font color='#FFFFFF'>"+turnoName.get(pos)+"</font>"));
}
mHolder.txt_ore.setText(oreName.get(pos));
return child;
}
Change your getView with the code posted above.
Hope it helps!
I have ListView with check boxes the app delete the checked items ;; and should delet teh items that have the same id with the checked items :
here's my code
private class CAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private ArrayList<Entity> list;
private Context context;
String Status;
CAdapter(Context context,
ArrayList<Entity> getC) {
this.context = context;
this.list = getC;
Status="";
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
class ViewHolder {
TextView Name;
TextView Desc;
Button deleteBtn;
CheckBox CBox;
}
public int getCount() {
return list.size();
}
public Object getItem(int position) {
return list.get(position);
}
public long getItemId(int position) {
return position;
}
#SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
final CEntity CObj = list.get(position);
if (convertView == null) {
convertView = mInflater.inflate(
R.layout.custom_list_view_confirmed, parent,
false);
holder = new ViewHolder();
holder.Name = (TextView) convertView
.findViewById(R.id.Name);
holder.Desc = (TextView) convertView
.findViewById(R.id.activity1);
holder.deleteBtn = (Button) convertView
.findViewById(R.id.deleteBtn);
holder.CBox=(CheckBox) convertView.findViewById(R.id.isCheck);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (CObj.getMystatus().equals(
context.getResources().getString(R.string.course_status_delete))) {
holder.status.setTextColor(Color.RED);
} else if (attemptedCourseObj.getMystatus().equals(
context.getResources().getString(R.string.course_status_pending))) {
holder.status.setTextColor(Color.GREEN);
} else if (attemptedCourseObj.getMystatus().equals(
context.getResources().getString(R.string.course_status_update))) {
holder.status.setTextColor(Color.BLUE);
}
holder.Name.setText(attemptedCourseObj.getCourseName());
holder.CBox.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(holder.CBox.isChecked()){
if(list.contains(getItem(position))){
list.remove(getItem(position));
}
}
}
});
//
return convertView;
}
}
the problem is when delete the checked it dosent delete the item that have the same id .
int pos=Data.CList.size();
SparseBooleanArray checked=CListView.getCheckedItemPositions();
for (int n = pos; n > 0; n--){
if (checked.get(n)){
code=Data.inList.get(n).getCCode();
Data.inList.remove(n);
}else if(CList.get(n).equal(code){
Data.inList.remove(n);
}
try to refresh the list with notifydatasetchanged and be sure that you delete the entire object from the list
You need to inform your adapter with the new modifications by giving the adapter the new dataset after removing the deleted elements from it and notify with the changes. You can do this as the following:
1)Add method into your adapter to set the new data as following:
public void setNewData(ArrayList<Entity> newEntities){
this.list = newEntities;
}
2)From the activity or the fragment call the previous method with the new data and call this line to notify the adapter with the changes
myAdapter.setNewData(myNewEntities);
myAdapter.notifyDataSetChanges();
Read this answer for more info about NotifyDataSetChanges() method
Is it possible to get an item view based on its position in the adapter and not in the visible views in the ListView?
I am aware of functions like getChildAt() and getItemIdAtPosition() however they provide information based on the visible views inside ListView. I am also aware that Android recycles views which means that I can only work with the visible views in the ListView.
My objective is to have a universal identifier for each item since I am using CursorAdapter so I don't have to calculate the item's position relative to the visible items.
Here's how I accomplished this. Within my (custom) adapter class:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
view = inflater.inflate(textViewResourceId, parent, false);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.name = (TextView) view.findViewById(R.id.name);
viewHolder.button = (ImageButton) view.findViewById(R.id.button);
viewHolder.button.setOnClickListener
(new View.OnClickListener() {
#Override
public void onClick(View view) {
int position = (int) viewHolder.button.getTag();
Log.d(TAG, "Position is: " +position);
}
});
view.setTag(viewHolder);
viewHolder.button.setTag(items.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).button.setTag(items.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
return view;
}
Essentially the trick is to set and retrieve the position index via the setTag and getTag methods. The items variable refers to the ArrayList containing my custom (adapter) objects.
Also see this tutorial for in-depth examples. Let me know if you need me to clarify anything.
See below code:
public static class ViewHolder
{
public TextView nm;
public TextView tnm;
public TextView tr;
public TextView re;
public TextView membercount;
public TextView membernm;
public TextView email;
public TextView phone;
public ImageView ii;
}
class ImageAdapter extends ArrayAdapter<CoordinatorData>
{
private ArrayList<CoordinatorData> items;
public FoodDriveImageLoader imageLoader;
public ImageAdapter(Context context, int textViewResourceId,ArrayList<CoordinatorData> items)
{
super(context, textViewResourceId, items);
this.items = items;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
ViewHolder holder = null;
if (v == null)
{
try
{
holder=new ViewHolder();
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new FoodDriveImageLoader(FoodDriveModule.this);
v = vi.inflate(R.layout.virtual_food_drive_row, null);
//System.out.println("layout is null.......");
holder.nm = (TextView) v.findViewById(R.id.name);
holder.tnm = (TextView) v.findViewById(R.id.teamname);
holder.tr = (TextView) v.findViewById(R.id.target);
holder.re = (TextView) v.findViewById(R.id.received);
holder.membercount = new TextView(FoodDriveModule.this);
holder.membernm = new TextView(FoodDriveModule.this);
holder.email = new TextView(FoodDriveModule.this);
holder.phone = new TextView(FoodDriveModule.this);
holder.ii = (ImageView) v.findViewById(R.id.icon);
v.setTag(holder);
}
catch(Exception e)
{
System.out.println("Excption Caught"+e);
}
}
else
{
holder=(ViewHolder)v.getTag();
}
CoordinatorData co = items.get(position);
holder.nm.setText(co.getName());
holder.tnm.setText(co.getTeamName());
holder.tr.setText(co.getTarget());
holder.re.setText(co.getReceived());
holder.ii.setTag(co.getImage());
imageLoader.DisplayImage(co.getImage(), FoodDriveModule.this , holder.ii);
if (co != null)
{
}
return v;
}
}
A better option is to identify using the data returned by the CursorAdapter rather than visible views.
For example if your data is in a Array , each data item has a unique index.
Here, Its very short described code, you can simple re-use viewholder pattern to increase listview performance
Write below code in your getview() method
ViewHolder holder = new ViewHolder();
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.skateparklist, null);
holder = new ViewHolder();
holder.headlineView = (TextView) convertView
.findViewById(R.id.textView1);
holder.DistanceView = (TextView) convertView
.findViewById(R.id.textView2);
holder.imgview = (NetworkImageView) convertView
.findViewById(R.id.imgSkatepark);
convertView.setTag(holder); //PLEASE PASS HOLDER AS OBJECT PARAM , CAUSE YOU CAN NOY PASS POSITION IT WILL BE CONFLICT Holder and Integer can not cast
//BECAUSE WE NEED TO REUSE CREATED HOLDER
} else {
holder = (ViewHolder) convertView.getTag();
}
// your controls/UI setup
holder.DistanceView.setText(strDistance);
......
return convertview
Listview lv = (ListView) findViewById(R.id.previewlist);
final BaseAdapter adapter = new PreviewAdapter(this, name, age);
confirm.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
View view = null;
String value;
for (int i = 0; i < adapter.getCount(); i++) {
view = adapter.getView(i, view, lv);
Textview et = (TextView) view.findViewById(R.id.passfare);
value=et.getText().toString();
Toast.makeText(getApplicationContext(), value,
Toast.LENGTH_SHORT).show();
}
}
});