Get values of edittext in listview - java

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();
}
});

Related

Hide or Show checkboxes inside Custom grid adapter for all Positions

I have to hide all the checkboxes for every [Position] product until User click button. When ever user clicks button check boxes will be show to select items for delete. Only check box will appear to change not whole grid view.
public class CartAdapter extends BaseAdapter {
Context context;
ArrayList<ProductCount> productCounts;
private LayoutInflater inflater;
private ImageButton plusButton;
private ImageButton minusButton;
private CheckBox selectToDelete;
private onDeleteCartItem onDeleteCartItem = null;
public CartAdapter(Context context, ArrayList<ProductCount> productCounts, onDeleteCartItem selectChangeListener) {
this.context = context;
this.productCounts = productCounts;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.onDeleteCartItem = selectChangeListener;
}
#Override
public int getCount() {
if(productCounts!=null)
return productCounts.size();
return 0;
}
#Override
public Object getItem(int position) {
if(productCounts!=null && position >=0 && position<getCount())
return productCounts.get(position);
return null;
}
#Override
public long getItemId(int position) {
if(productCounts!=null && position >=0 && position<getCount()){
ProductCount temp = productCounts.get(position);
return productCounts.indexOf(temp);
}
return 0;
}
public class ProductsListHolder{
public ImageView cart_item_img;
public TextView cart_item_desc;
public TextView cart_item_count;
public TextView cart_item_price_tag;
public TextView cart_item_price;
public ImageButton cart_item_minus;
public ImageButton cart_item_plus;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ProductsListHolder productsListHolder;
if(view == null){
view = inflater.inflate(R.layout.cart_adapter, parent, false);
productsListHolder = new ProductsListHolder();
productsListHolder.cart_item_img = (ImageView) view.findViewById(R.id.cart_item_img);
productsListHolder.cart_item_desc = (TextView) view.findViewById(R.id.cart_item_desc);
productsListHolder.cart_item_count = (TextView) view.findViewById(R.id.cart_item_count);
productsListHolder.cart_item_price_tag = (TextView) view.findViewById(R.id.cart_item_price_tag);
productsListHolder.cart_item_price = (TextView) view.findViewById(R.id.cart_item_price);
plusButton = (ImageButton) view.findViewById(R.id.cart_item_plus);
minusButton = (ImageButton) view.findViewById(R.id.cart_item_minus);
selectToDelete = (CheckBox) view.findViewById(R.id.select_to_delete);
selectToDelete.setTag(position);
view.setTag(productsListHolder);
}
else{
productsListHolder = (ProductsListHolder) view.getTag();
}
final ProductCount cat = productCounts.get(position);
selectToDelete.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
if(onDeleteCartItem != null){
onDeleteCartItem.onSelectToDelete((Integer)buttonView.getTag(),isChecked);
}
}
}
});
minusButton.setOnClickListener(new View.OnClickListener() {
int itemcount = 0;
#Override
public void onClick(View v) {
itemcount = productCounts.get(position).getCount();
productCounts.get(position).setCount(itemcount-1);
setProduct(position,productsListHolder,cat);
}
});
plusButton.setOnClickListener(new View.OnClickListener() {
int itemcount = 0;
#Override
public void onClick(View v) {
itemcount = productCounts.get(position).getCount();
productCounts.get(position).setCount(itemcount+1);
setProduct(position,productsListHolder,cat);
}
});
setProduct(position,productsListHolder,cat);
return view;
}
private void setProduct(int position, final ProductsListHolder productsListHolder, ProductCount pCount) {
Picasso.with(context).load(pCount.products.getImageResours()).into(new Target(){
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
productsListHolder.cart_item_img.setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
#Override
public void onBitmapFailed(final Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
}
});
productsListHolder.cart_item_desc.setText(pCount.getProducts().getDescription());
productsListHolder.cart_item_price_tag.setText((String.valueOf(pCount.getCount()).concat(" x Rs. ").concat(String.valueOf((pCount.products.getPrice())))));
productsListHolder.cart_item_price.setText("Rs. ".concat(String.valueOf(pCount.getCount()* pCount.products.getPrice())));
productsListHolder.cart_item_count.setText(String.valueOf(pCount.getCount()));
}
#Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
}
Just handling your checkBox in your adapter because you got the position then can hide/show, OnClickListener, OnCheckedChangeListener however you want.
Reference to my answer here: Is there a simple way to check all CheckBox items in custimize BaseAdapter in android?

How can I change text within a listview, using a adapter

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;
}

Android-Studio I get no display in video thumbnail getView method

I need to display the video in thumbnails style but i get no display, if anyone know what i'am done wrong please give me an idea to follow.
I get the idea in this tutorial
http:android-er.blogspot.com/2011/05/display-video-thumbnail-in-listview.html
public class RemarksAdapter extends ArrayAdapter<RemarksInformation> {
Context context;
LayoutInflater inflater;
List<RemarksInformation> remarksInformationList;
public RemarksAdapter(Context context, int resourceId, List<RemarksInformation> remarksInformationList) {
super(context, resourceId, remarksInformationList);
this.context = context;
this.remarksInformationList = remarksInformationList;
inflater = LayoutInflater.from(context);
}
static class RemarksHolder{
TextView remarks;
TextView image_name;
TextView image_path;
TextView video_name;
TextView video_path;
TextView date_send;
TextView time_send;
TextView remarks_by;
RelativeLayout image_wrapper;
RelativeLayout video_wrapper;
ImageView thumbnail;
}
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
RemarksHolder holder = null;
View v = convertView;
if(v == null){
v = inflater.inflate(R.layout.item_view_remarks, null);
holder = new RemarksHolder();
holder.remarks = (TextView)v.findViewById(R.id.txt_remarks);
holder.date_send = (TextView)v.findViewById(R.id.txt_date_send);
holder.time_send = (TextView)v.findViewById(R.id.txt_time_send);
holder.image_name = (TextView)v.findViewById(R.id.image_name);
holder.image_path = (TextView)v.findViewById(R.id.image_path);
holder.video_name = (TextView)v.findViewById(R.id.video_name);
holder.video_path = (TextView)v.findViewById(R.id.video_path);
holder.remarks_by = (TextView)v.findViewById(R.id.remarks_by);
holder.image_wrapper = (RelativeLayout)v.findViewById(R.id.image_wrapper);
holder.video_wrapper = (RelativeLayout)v.findViewById(R.id.video_wrapper);
holder.thumbnail = (ImageView)v.findViewById(R.id.vid);
v.setTag(holder);
}else{
holder = (RemarksHolder)v.getTag();
}
holder.remarks.setText(remarksInformationList.get(position).getRemarks());
holder.image_name.setText(remarksInformationList.get(position).getImage_name());
holder.image_path.setText(remarksInformationList.get(position).getImage_path());
holder.video_name.setText(remarksInformationList.get(position).getVideo_name());
holder.video_path.setText(remarksInformationList.get(position).getVideo_path());
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(remarksInformationList
.get(position).getVideo_path(), Thumbnails.MICRO_KIND);
holder.thumbnail.setImageBitmap(bmThumbnail); //Get no display
holder.date_send.setText(remarksInformationList.get(position).getDate_send());
holder.time_send.setText(remarksInformationList.get(position).getTime_send());
holder.remarks_by.setText(remarksInformationList.get(position).getRemarks_by());
holder.image_wrapper.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((ListView) parent).performItemClick(v, position, 0);
}
});
holder.video_wrapper.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((ListView) parent).performItemClick(v, position, 0);
}
});
return v;
}

how to change particularly one row textview value while click the button in custome listview?

I have a custom list view with base adapter. i have tried to increment and decrement particularly one row textview value. it is working but all the row textview value is changed while click the button. how can i changed particularly one row textview value. plese suggest me.
public class BreakfastListAdapter extends BaseAdapter {
private Context context;
private String[] number;
private int[] imageid;
ImageView plus1, minus1;
TextView value1;
int a = 0;
public BreakfastListAdapter(Context c, String[] number, int[] imageid) {
context = c;
this.imageid = imageid;
this.number = number;
}
#Override
public int getCount() {
return number.length;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
// convertView = new View(context);
convertView = inflater.inflate(R.layout.secondadapter, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.text);
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
plus1 = (ImageView) convertView.findViewById(R.id.plus);
minus1 = (ImageView) convertView.findViewById(R.id.minus);
value1 = (TextView) convertView.findViewById(R.id.value);
textView.setText(number[position]);
imageView.setImageResource(imageid[position]);
value1.setText(String.valueOf(a));
System.out.println(a + "dddddddddddddd");
plus1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
a = a + 1;
value1.setText(String.valueOf(a));
Toast.makeText(context, String.valueOf(a), 1000).show();
System.out.println("######################");
System.out.println(a);
notifyDataSetChanged();
}
});
return convertView;
}
}
You need to keep the value for each row and not one for all the rows.
Change your int a in an int[] a and keep each value of each row.
You will have the following listener:
#Override
public void onClick(View v) {
a[position] = a[position] + 1;
value1.setText(String.valueOf(a[position]));
Toast.makeText(context, String.valueOf(a[position]), 1000).show();
System.out.println("######################");
System.out.println(a[position]);
notifyDataSetChanged();
}
Here is the complete code:
public class BreakfastListAdapter extends BaseAdapter {
private Context context;
private String[] number;
private int[] imageid;
ImageView plus1, minus1;
TextView value1;
int a[];
public BreakfastListAdapter(Context c, String[] number, int[] imageid) {
context = c;
this.imageid = imageid;
this.number = number;
this.a = new int[number.length];
}
#Override
public int getCount() {
return number.length;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
// convertView = new View(context);
convertView = inflater.inflate(R.layout.secondadapter, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.text);
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
plus1 = (ImageView) convertView.findViewById(R.id.plus);
minus1 = (ImageView) convertView.findViewById(R.id.minus);
value1 = (TextView) convertView.findViewById(R.id.value);
textView.setText(number[position]);
imageView.setImageResource(imageid[position]);
value1.setText(String.valueOf(a[position]));
System.out.println(a[position] + "dddddddddddddd");
plus1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
a[position] = a[position] + 1;
value1.setText(String.valueOf(a[position]));
Toast.makeText(context, String.valueOf(a[position]), 1000).show();
System.out.println("######################");
System.out.println(a[position]);
notifyDataSetChanged();
}
});
return convertView;
}
}
You should setText string to perticular row TextView.
Every row is referenced through convertView so we will use it
Modification is :
plus1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
a = a + 1;
// this is change
convertView.value1.setText(String.valueOf(a));
Toast.makeText(context, String.valueOf(a), 1000).show();
System.out.println("######################");
System.out.println(a);
notifyDataSetChanged();
}
We need to set a value to 0 at last :
// reset a value at end of getView() method
a = 0;
So that when next row is displayed, a value is 0 and it starts increment from 0
Try this one remove
a = a + 1;//because this is a global variable in the class
change value1.setText(""+(a+1));
if this's not the problem declare an array/arraylist with size similar to listview size and populate arraylist inside the constructer with all values set to 0.Then inside getview() method
int currentposition=position;
plus1.setTag(currentposition);
value1.setText(arraylist.get(currentposition));
plus1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int btnvalue=Integer.parseInt(plus1.getTag().toString());
arraylist.set(btnvalue,(Integer.parseInt(arraylist.get(btnvalue)))+1);
notifydatasetchanged();
}
});
Implement ViewHolder Class to maintain a separate copy of their widgets for example
ViewHolder{
TextView t1;
Imageview i1,i2;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.secondadapter, null);
holder = new ViewHolder();
holder.t1 = (TextView) convertView.findViewById(R.id.text);
holder.i1 =convertView.findViewById(R.id.imageView1);
holder.i2 =convertView.findViewById(R.id.imageView1);
convertView.setTag(holder);
}else
{
ViewHolder holder = (ViewHolder) convertView.getTag();
}
holder.t1.setText(number[position]);
holder.i1.setImageResource(imageid[position]);
holder.t1.setText(String.valueOf(a));
System.out.println(a + "dddddddddddddd");
holdert1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
a = a + 1;
holder.t1.setText(String.valueOf(a));
Toast.makeText(context, String.valueOf(a), 1000).show();
System.out.println("######################");
System.out.println(a);
notifyDataSetChanged();
}
});
return convertView
}

Adding a new row on button click to a list view

I want to add a new row on clicking add button in a list view in android.
Can someone help me out?
Here is the code I have so far:
public class prsnlhstry<EventArgs> extends Activity implements OnItemClickListener {
public static ArrayList<String> arr_sort_textview1= null;
public static ArrayList<String> arr_sort_textview2=null;
public static ArrayList<String> arr_sort_textview3=null;
public Resources ApptResources= null;
private ContextWrapper mycontext;
tododata todo;
int clickcounter = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lv= (ListView)findViewById(R.id.listview);
todo = new tododata(this);
List<listObject> List = new ArrayList<listObject>();
for(int i = 0; i <= 5; i++){
listObject lo = new listObject();
lo.grade = Integer.toString(i);
lo.reason = Integer.toString(i);
lo.school = Integer.toString(i);
List.add(lo);
}
CustomAdapter ca = new CustomAdapter(this);
lv = (ListView)findViewById(R.id.listview);
lv.setAdapter(ca);
lv.setOnItemClickListener(this);
ca.notifyDataSetChanged();
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Toast.makeText(prsnlhstry.this, "Row Added Successfully", Toast.LENGTH_SHORT).show();
}
});
}
private class listObject {
String grade;
String school;
String reason;
}
public class CustomAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public CustomAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return todo.getLength();
}
#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) {
ViewHolder holder;
String temp = null;
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(R.layout.grid_item, null);
// Creates a ViewHolder and store references to the views
// we want to bind data to.
holder = new ViewHolder();
holder.textview1 = (TextView) convertView.findViewById(R.id.item2);
holder.textview2 = (TextView) convertView.findViewById(R.id.item3);
holder.textview3 = (TextView) convertView.findViewById(R.id.item4);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textview1.setText(todo.getgrade(position));
holder.textview2.setText(todo.getschool(position));
holder.textview3.setText(todo.getreason(position));
return convertView;
}
}
static class ViewHolder {
TextView textview1;
TextView textview2;
TextView textview3;
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
}
Just add the item to your list and refresh the adapter, nothing special.
You need to increment your "tododata" data structure on button click and then call to notifyDataSetChanged() method:
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
todo.addNewRow();
ca.notifyDataSetChanged();
Toast.makeText(prsnlhstry.this, "Row Added Successfully", Toast.LENGTH_SHORT).show();
}
});
To compile the above code you will need to define "ca" variable as the final one, or make it class member.
I hope it helps.

Categories

Resources