I have a problem.
In my app, i've got a custom ListView with two Button for each Row.
I've created a class extends ArrayAdapter where i try to manage the OnClickListner of the Button, but it Doesn't work. If i press a buttton, nothing happens.
This is my class:
public class AdapterMovimentazioni extends ArrayAdapter<ItemWithIdMov> {
private Context context;
private ArrayList<ItemWithIdMov> items;
private LayoutInflater vi;
public AdapterMovimentazioni(Context context, ArrayList<ItemWithIdMov> items) {
super(context, 0, items);
this.context = context;
this.items = items;
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
final ItemWithIdMov i = items.get(position);
if (convertView == null) {
convertView = vi.inflate(R.layout.item_movimentazioni, null);
holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.imageMov);
holder.data = (TextView) convertView.findViewById(R.id.DataMov);
holder.importo = (TextView) convertView.findViewById(R.id.ImportoMov);
holder.locale = (TextView) convertView.findViewById(R.id.localeMov);
holder.delete = (Button) convertView.findViewById(R.id.ButtonDeleteMov);
holder.set = (Button) convertView.findViewById(R.id.ButtonSetMov);
holder.delete.setTag(holder);
holder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "DELETEEEEEE", Toast.LENGTH_LONG);
}
});
holder.set.setTag(holder);
holder.set.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "SET", Toast.LENGTH_LONG);
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (i != null) {
holder.icon.setImageResource(i.getIcon());
holder.data.setText(i.getData());
holder.importo.setText(i.getImporto());
holder.locale.setText(i.getLocName());
}
return convertView;
}
private class ViewHolder {
public ViewHolder() {
}
protected Button delete;
protected Button set;
protected ImageView icon;
protected TextView data;
protected TextView importo;
protected TextView locale;
}
Can you help me??
Thank you
use Toast Like
Toast.makeText(context, "SET", Toast.LENGTH_LONG).show();
change your getview method after createing views decleration onClicklistener;
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
final ItemWithIdMov i = items.get(position);
if (convertView == null) {
convertView = vi.inflate(R.layout.item_movimentazioni, null);
holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.imageMov);
holder.data = (TextView) convertView.findViewById(R.id.DataMov);
holder.importo = (TextView) convertView.findViewById(R.id.ImportoMov);
holder.locale = (TextView) convertView.findViewById(R.id.localeMov);
holder.delete = (Button) convertView.findViewById(R.id.ButtonDeleteMov);
holder.set = (Button) convertView.findViewById(R.id.ButtonSetMov);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "DELETEEEEEE", Toast.LENGTH_LONG);
}
});
holder.set.setTag(holder);
holder.set.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "SET", Toast.LENGTH_LONG);
}
});
if (i != null) {
holder.icon.setImageResource(i.getIcon());
holder.data.setText(i.getData());
holder.importo.setText(i.getImporto());
holder.locale.setText(i.getLocName());
}
return convertView;
}
Related
Can you help me out, I'm learning! ;-)
I have two buttons "+" and "-" and I want them to increase or decrease the amount by one up or one down. How do I make sure that it will only have effect on the right textview using an adapter.
Now all the buttons only effects the first one. I know I have to get the position/id of the array. But I don't know how.
btw
Merk = Brand
Aantal = Amount
public class ListViewDemo2 extends Activity {
private ArrayList<String> data = new ArrayList<String>();
int aantal = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view_demo2);
ListView lv = (ListView) findViewById(R.id.bestel_lijst);
lv.setAdapter(new MyListAdapter(this, R.layout.list_item, data));
generateListContent();
}
private void generateListContent(){
for (int i =0; i < 55; i++){
data.add("this is row number: " + i);
}
}
#Override
public boolean onCreateOptionsMenu (Menu menu){
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings){
return true;
}
return super.onOptionsItemSelected(item);
}
private class MyListAdapter extends ArrayAdapter<String>{
private int layout;
public MyListAdapter(Context context, int resource, List<String> objects) {
super(context, resource, objects);
layout = resource;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder mainViewholder = null;
if(convertView == null){
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(layout, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.Merk = (TextView) convertView.findViewById(R.id.Merk);
viewHolder.Aantal = (TextView) convertView.findViewById(R.id.Aantal);
viewHolder.btnup = (Button) convertView.findViewById(R.id.Bup);
viewHolder.btndown = (Button) convertView.findViewById(R.id.Bdown);
viewHolder.btndown.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
aantal = aantal-1;
displayAantal(aantal);
}
});
viewHolder.btnup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
aantal = aantal+1;
displayAantal(aantal);
}
});
convertView.setTag(viewHolder);
}
else {
mainViewholder = (ViewHolder)convertView.getTag();
mainViewholder.Merk.setText(getItem(position));
}
return convertView;
}
}
public class ViewHolder {
TextView Merk;
TextView Aantal;
Button btnup;
Button btndown;
}
public void displayAantal(int aantal) {
TextView aantalView = (TextView) findViewById(R.id.Aantal);
aantalView.setText(String.valueOf(aantal));
}
}
your problem seems to be in your displayAantal(int) method, in particular, in this line:
TextView aantalView = (TextView) findViewById(R.id.Aantal);
You do not need to re-initialize that field here, since it is already initialized inside getView():
viewHolder.Aantal = (TextView) convertView.findViewById(R.id.Aantal);
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder mainViewholder = null;
if(convertView == null){
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(layout, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.Merk = (TextView) convertView.findViewById(R.id.Merk);
viewHolder.Aantal = (TextView) convertView.findViewById(R.id.Aantal);
viewHolder.btnup = (Button) convertView.findViewById(R.id.Bup);
viewHolder.btndown = (Button) convertView.findViewById(R.id.Bdown);
convertView.setTag(viewHolder);
}
else {
mainViewholder = (ViewHolder)convertView.getTag();
}
String str = getItem(position);
mainViewholder.Merk.setText(str);
viewHolder.btndown.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
//just handle the data ,then call adapter.notifyDataSetChanged();
}
});
viewHolder.btnup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
//just handle the data ,then call adapter.notifyDataSetChanged();
}
});
return convertView;
}
I want get values of edittext in listview.
This is my CustomAdapter.java
public class CustomAdapter extends BaseAdapter {
Context context;
List<RowItem> rowItem;
ImageView imgIcon, add_cart;
TextView txtTitle;
EditText colli, prezzo, quantita;
String colliStr, prezzoStr, quantitaStr;
ArrayList<String> ArrayPrezzo = new ArrayList<String>();
ArrayList<String> ArrayQuantita = new ArrayList<String>();
ArrayList<String> ArrayColli = new ArrayList<String>();
CustomAdapter(Context context, List<RowItem> rowItem) {
this.context = context;
this.rowItem = rowItem;
}
#Override
public int getCount() {
return rowItem.size();
}
#Override
public Object getItem(int position) {
return rowItem.get(position);
}
#Override
public long getItemId(int position) {
return rowItem.indexOf(getItem(position));
}
#Override
public boolean areAllItemsEnabled() {
return false;
}
#Override
public boolean isEnabled(int position) {
return false;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.single_row, null);
}
imgIcon = (ImageView) convertView.findViewById(R.id.icon);
txtTitle = (TextView) convertView.findViewById(R.id.title);
add_cart = (ImageView) convertView.findViewById(R.id.icon);
colli = (EditText) convertView.findViewById(R.id.editText3);
prezzo = (EditText) convertView.findViewById(R.id.editText2);
quantita = (EditText) convertView.findViewById(R.id.editText);
add_cart.setFocusable(true);
add_cart.setClickable(true);
final RowItem row_pos = rowItem.get(position);
// setting the image resource and title
imgIcon.setImageResource(R.drawable.product);
txtTitle.setText(row_pos.getTitle());
add_cart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// HERE I WANT GET THE VALUES OF EDITTEXT;
}
});
return convertView;
}
can someone help me please? In ly listview there are:
textview | edittext1 | edittext2 | edittext3 | imageview
I don't know how to get values of edittext at position current when i click the button.
Can you make a example with my code?
Thnank you
UPDATE:
I have edited the listener:
add_cart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
prezzoStr = prezzo.getText().toString();
Toast.makeText(context, prezzoStr, Toast.LENGTH_SHORT)
.show();
}
});
but prezzoStr is empty. Toast doesn't show nothing.
I think need use row_pos variable for getting the value of a determinate edittext.
Help please
It's not difficult
add_cart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String colliValue = colli.getText().toString());
String prezzoValue = prezzo.getText().toString());
String quantitaValue = quantita.getText().toString());
}
});
You have to get parent view and then find text view by id:
add_cart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView prezzo = (TextView) findByIdRecursively(v, R.id.editText2);
String prezzoStr = prezzo.getText().toString();
}
});
...
public View findByIdRecursively(View view, int targetId) {
View result = view.findViewById(targetId);
if (result != null) {
return result;
}
View parent = (View) view.getParent();
if (parent == null) {
return null;
}
return findByIdRecursively(parent, targetId);
}
The view in onClick is the view that was clicked (add_cart in this case)
... or you can do:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
...
add_cart = (ImageView) convertView.findViewById(R.id.icon);
add_cart.setTag(convertView);
add_cart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView prezzo = (TextView) ((View)v.getTag()).findViewById(R.id.editText2);
String prezzoStr = prezzo.getText().toString();
}
});
When I am checked any item like (position 0) its automatically checked randomly any item (like position 7) and when I scroll down or up the check position will be change every time... I am fed up from that problem...??
public class contactAdpter extends ArrayAdapter<ContactItem> {
Context context;
List<ContactItem> list;
public contactAdpter(Context context, int resource, List<ContactItem> items) {
super(context, resource,items);
this.context = context;
this.list = items;
}
static class ViewHolder {
ImageView imageview;
TextView tv1;
TextView tv2;
CheckBox ch;
}
#Override
public int getCount() {
return list.size();
}
#Override
public int getPosition(ContactItem item) {
return super.getPosition(item);
}
#Override
public long getItemId(int id) {
return id;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
View view = convertView;
ContactItem contactItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
view = mInflater.inflate(R.layout.contact_list, null);
holder = new ViewHolder();
holder.tv1 = (TextView) view.findViewById(R.id.name);
holder.tv2 = (TextView) view.findViewById(R.id.number);
holder.ch = (CheckBox) view.findViewById(R.id.checkbox1);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.tv1.setText(contactItem.getConatct_name());
holder.tv2.setText(contactItem.getNumber());
return view;
}
}
in ContactItem you need to maintain Checked Status. and change getView as follows,
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
View view = convertView;
ContactItem contactItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
view = mInflater.inflate(R.layout.contact_list, null);
holder = new ViewHolder();
holder.tv1 = (TextView) view.findViewById(R.id.name);
holder.tv2 = (TextView) view.findViewById(R.id.number);
holder.ch = (CheckBox) view.findViewById(R.id.checkbox1);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.tv1.setText(contactItem.getConatct_name());
holder.tv2.setText(contactItem.getNumber());
holder.ch.setOnCheckedChangeListener(null);
holder.ch.setChecked(contactItem.getCheckedStatus());
holder.ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
contactItem.setCheckedStatus(isChecked);
}
});
return view;
}
you have to add another variable in ContactItem like below:
private boolean isSelected;
generate getter and setter method of this variable after that in your adapter :
public class contactAdpter extends ArrayAdapter {
Context context;
List<ContactItem> list;
public contactAdpter(Context context, int resource, List<ContactItem> items) {
super(context, resource,items);
this.context = context;
this.list = items;
}
static class ViewHolder {
ImageView imageview;
TextView tv1;
TextView tv2;
CheckBox ch;
}
#Override
public int getCount() {
return list.size();
}
#Override
public int getPosition(ContactItem item) {
return super.getPosition(item);
}
#Override
public long getItemId(int id) {
return id;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
View view = convertView;
ContactItem contactItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
view = mInflater.inflate(R.layout.contact_list, null);
holder = new ViewHolder();
holder.tv1 = (TextView) view.findViewById(R.id.name);
holder.tv2 = (TextView) view.findViewById(R.id.number);
holder.ch = (CheckBox) view.findViewById(R.id.checkbox1);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.tv1.setText(contactItem.getConatct_name());
holder.tv2.setText(contactItem.getNumber());
if(contactItem.isSelected){
holder.ch.isChecked(true);
} else {
holder.ch.isChecked(false);
}
holder.ch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(contactItem.isSelected){
holder.ch.isChecked(false);
contactItem.setChecked(false);
} else {
holder.ch.isChecked(true);
contactItem.setChecked(true);
}
notifyDatasetChanged();
}
});
return view;
}
}
I have created a Custom Adapter to manage some Buttons inside each ListView item. If I scroll-down the list, and I click a button, the adapter take a wrong position.
LISTVIEW
item 1
item 2
item 3
item 4
item 5
item 6
item 7
POSITION AFTER CLICK
0
1
2
3
4
5
0
This is my adapter:
public DoubleListAdapter(Context context, ArrayList<DoubleListItems> items,
String Tag) {
super(context, 0, items);
this.Tag = Tag;
this.context = context;
this.items = items;
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
final int Position = position;
if (convertView == null) {
convertView = vi.inflate(R.layout.double_list_item, null);
holder = new ViewHolder();
final DoubleListItems i = (DoubleListItems) items.get(position);
holder.item = i;
holder.Icon = (ImageView) convertView
.findViewById(R.id.IconaDoubleList);
holder.Title = (TextView) convertView
.findViewById(R.id.TitoloDoubleList);
holder.SecondLineDesc = (TextView) convertView
.findViewById(R.id.SecondaLineaDesc);
holder.SecondLineValue = (TextView) convertView
.findViewById(R.id.SecondaLineaValue);
holder.ThirdLineDesc = (TextView) convertView
.findViewById(R.id.TerzaLineaDesc);
holder.ThirdLineValue = (TextView) convertView
.findViewById(R.id.TerzaLineaValue);
holder.Delete = (Button) convertView
.findViewById(R.id.ButtonDeleteItem);
holder.Set = (Button) convertView.findViewById(R.id.ButtonSetiItem);
holder.Delete.setTag(holder);
holder.Delete.setOnClickListener(new OnClickListener() {
holder.Set.setTag(holder);
holder.Set.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Log.e("DOUBLELIST ADAPTER ", "Position: " + Position);
String Code = i.getKey();
// String Code = holder.item.getKey();
Intent intent;
Costanti.curLocale = Costanti.LocaliLavorati.Item("L"
+ Code);
intent = new Intent(context, IncassiTab.class);
if (Costanti.curLocale != null) {
context.startActivity(intent);
} else {
Toast.makeText(context, "Locale nullo",
Toast.LENGTH_SHORT);
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final DoubleListItems i = holder.item;
if (i != null) {
holder.Set.setVisibility(View.GONE);
holder.Delete.setVisibility(View.GONE);
holder.Icon.setImageResource(i.getIcon());
holder.Title.setText(i.getTitle());
holder.SecondLineDesc.setText(i.getSecondLineDesc());
if (i.getType().equals("N")) {
holder.SecondLineDesc.setTextColor(context.getResources()
.getColor(R.color.grigio));
}
if (!i.getSecondLineValue().equals("")) {
holder.SecondLineValue.setVisibility(View.VISIBLE);
holder.SecondLineDesc.setTextColor(context.getResources()
.getColor(R.color.orange));
holder.Icon.setImageResource(i.getIcon());
holder.Title.setText(i.getTitle());
holder.SecondLineDesc.setText(i.getSecondLineDesc());
holder.SecondLineValue.setText(i.getSecondLineValue());
if (!i.getThirdLineDesc().equals("")) {
holder.Set.setVisibility(View.VISIBLE);
holder.Delete.setVisibility(View.VISIBLE);
holder.ThirdLineDesc.setVisibility(View.VISIBLE);
holder.ThirdLineValue.setVisibility(View.VISIBLE);
holder.ThirdLineDesc.setText(i.getThirdLineDesc());
holder.ThirdLineValue.setText(i.getThirdLineValue());
holder.Delete.setVisibility(View.VISIBLE);
holder.Set.setVisibility(View.VISIBLE);
} else {
holder.ThirdLineDesc.setVisibility(View.GONE);
holder.ThirdLineDesc.setVisibility(View.GONE);
}
} else {
holder.SecondLineValue.setVisibility(View.GONE);
holder.ThirdLineDesc.setVisibility(View.GONE);
holder.ThirdLineValue.setVisibility(View.GONE);
holder.Set.setVisibility(View.GONE);
holder.Delete.setVisibility(View.GONE);
}
}
return convertView;
}
private class ViewHolder {
public ViewHolder() {
}
protected DoubleListItems item;
protected Button Delete;
protected Button Set;
protected ImageView Icon;
protected TextView Title;
protected TextView SecondLineDesc;
protected TextView SecondLineValue;
protected TextView ThirdLineDesc;
protected TextView ThirdLineValue;
}
This is the solution:
if (convertView == null) {
Your code
}else{
Your code
}
holder.Set.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Your code
}
}
How can I display text in TextView at get view after this call
ListAdapter adapter = new MyCustomAdapter (
ManageSection.this, studentList,
R.layout.list_student, new String[] { TAG_StudentID,
TAG_StudentNo,TAG_FullName},
new int[] { R.id.StudentID, R.id.StudentNo,R.id.FullName});
setListAdapter(adapter);
and the class MyCustomAdapter has a get view, I will display the text
holder.FullName= (TextView) convertView.findViewById(R.id.FullName);
holder.FullName.setText();
holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo);
holder.StudentNo.setText();
So at set text what should I write cause I do
no=student.get(holder.position).get(TAG_StudentNo);
name =student.get(holder.position).get(TAG_FullName);
and take no, name but the text is duplicated in the whole list
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null)
{
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(resource, parent, false);
holder = new ViewHolder();
no=student.get(holder.position).get(TAG_StudentNo);
name =student.get(holder.position).get(TAG_FullName);
holder.StudentID= (TextView) convertView.findViewById(R.id.StudentID);
holder.FullName= (TextView) convertView.findViewById(R.id.FullName);
holder.FullName.setText();
holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo);
holder.StudentNo.setText();
holder.DeleteStudent = (ImageView) convertView.findViewById(R.id.DeleteStudent);
holder.AlertIcon = (ImageView) convertView.findViewById(R.id.Alert);
// add a listener for phone call
holder.DeleteStudent.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
id = student.get(holder.position).get(TAG_StudentID);
Toast.makeText(getContext(),id,Toast.LENGTH_LONG).show();
}
});
holder.AlertIcon.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// String email = MyCustomAdapter.listMap.get(holder.position).get("email");
// ActivityHelper.startActivity(ActivityManager.EMAIL, email);
}
});
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.position = position;
return convertView;
}
private static class ViewHolder
{
ImageView DeleteStudent;
ImageView AlertIcon;
TextView StudentID, StudentNo ,FullName;
int position;
}
}
Can anyone tell me what the problem is here?
Try this code.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null)
{
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(resource, parent, false);
holder = new ViewHolder();
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.position = position;
no=student.get(holder.position).get(TAG_StudentNo);
name =student.get(holder.position).get(TAG_FullName);
holder.StudentID= (TextView) convertView.findViewById(R.id.StudentID);
holder.FullName= (TextView) convertView.findViewById(R.id.FullName);
holder.FullName.setText();
holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo);
holder.StudentNo.setText();
holder.DeleteStudent = (ImageView) convertView.findViewById(R.id.DeleteStudent);
holder.AlertIcon = (ImageView) convertView.findViewById(R.id.Alert);
// add a listener for phone call
holder.DeleteStudent.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
id = student.get(holder.position).get(TAG_StudentID);
Toast.makeText(getContext(),id,Toast.LENGTH_LONG).show();
}
});
holder.AlertIcon.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// String email = MyCustomAdapter.listMap.get(holder.position).get("email");
// ActivityHelper.startActivity(ActivityManager.EMAIL, email);
}
});
return convertView;
}
private static class ViewHolder
{
ImageView DeleteStudent;
ImageView AlertIcon;
TextView StudentID, StudentNo ,FullName;
int position;
}
}
What you were doing is just setting the data only when the convertView is null and if not you just returning the view after some Holder operation. You need to set Text etc, in the textView in every case. If you need more explanation, please ask.
its simple buddy U just have to put this line instead of blank setText()
no=student.get(holder.position).get(TAG_StudentNo);// the roll_number string
name =student.get(holder.position).get(TAG_FullName);//full name string
holder.StudentID= (TextView) convertView.findViewById(R.id.StudentID);
holder.FullName= (TextView) convertView.findViewById(R.id.FullName);
holder.FullName.setText(name);//pass fullname
holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo);
holder.StudentNo.setText(no);//pass roll no.
you just have to pass the no and 'namevariable tosetText()` method.