My Problem was solved, anyway thank you for all. I need to edit getView() Method inside the EfficientAdapter class
public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView == null){ convertView = mInflater.inflate(R.layout.jobboards, null); holder = new ViewHolder(); holder.textLine = (TextView) convertView.findViewById(R.id.textLine); holder.buttonLine =(Button) convertView.findViewById(R.id.buttonLine); convertView.setTag(holder); } holder =(ViewHolder) convertView.getTag(); holder.textLine.setText((String)getItem(position)); convertView.setOnClickListener(new OnClickListener() { public void onClick(View v) { //startActivity(new Intent(EfficientAdapter.class, JobboardHeadLines.class).addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)); callJobboardHeadLinesActivity(String.valueOf(position),v,data.get(position).toString().toUpperCase().trim()); Toast.makeText(context, "Click-" + String.valueOf(position), Toast.LENGTH_SHORT).show(); } }); holder.buttonLine.setOnClickListener(new OnClickListener() { public void onClick(View v) { data.remove(position); notifyDataSetChanged(); Log.i(TAG, "Delete button pressed at position" + position); Toast.makeText(context, "Delete-" + String.valueOf(position), Toast.LENGTH_SHORT).show(); } }); return convertView; } On Mar 21, 10:32 pm, Doug <beafd...@gmail.com> wrote: > You can do this the same way you would do anything that changes the data > displayed in a ListView. Make the data change in the adapter that's hooked > up to the ListView, then call notifyDataSetChanged on the adapter. That > will cause the ListView to refresh with the new data in the adapter. > > Doug > > > > > > > > On Tuesday, March 20, 2012 7:34:00 AM UTC-7, radhakrishna wrote: > > > @seshu > > > You mean updating onListItemClick method in > > TestListItemsView1Activity : > > --------------------------------------------------------------------------- > > ------------------ > > > protected void onListItemClick(ListView l, View v, int position, > > long id) { > > super.onListItemClick(l, v, position, id); > > Toast.makeText(this, "Click-" + String.valueOf(position), > > Toast.LENGTH_SHORT).show(); > > dataValues..remove(position); > > } > > --------------------------------------------------------------------------- > > ------------------ > > > This does not work for me, I need to click remove button to remove > > listrow. > > > My ListView contains [TextView and delete Button], I need to delete > > list row, when I click on Delete button, When I click On Delete button > > it will not enter into onListItemClick method under > > TestListItemsView1Activity class , it will enter only when I select > > TextView (Text). > > > Onlick method for delete button located in EfficientAdapter class. > > > On Mar 20, 2:20 pm, Seshu <s.seshu...@gmail.com> wrote: > > > dataValues..remove(position); will deletes the entire row only... > > > > On Mar 20, 6:58 pm, radhakrishna <radhakrishna.kotako...@gmail.com> > > > wrote: > > > > > Thank you for your response Seshu, But I would like to delete list > > > > row, when I click on delete button from List view. > > > > > On Mar 20, 1:12 pm, Seshu <s.seshu...@gmail.com> wrote: > > > > > > Hi radhakrishna, > > > > > if u want to delete the list row in the list view. > > > > > > protected void onListItemClick(ListView l, View v, int position, > > > > > long id) { > > > > > super.onListItemClick(l, v, position, id); > > > > > Toast.makeText(this, "Click-" + String.valueOf(position), > > > > > Toast.LENGTH_SHORT).show(); > > > > > > dataValues..remove(position); > > > > > > } > > > > > > Thanks and Regards, > > > > > S.Seshu > > > > > > On Mar 20, 2:41 am, radhakrishna <radhakrishna.kotako...@gmail.com> > > > > > wrote: > > > > > > > Hi All, > > > > > > > I am trying to remove an item from listview, > > > > > > My Listview contains Text and Delete button in each row, > > > > > > when I click on delete button its removing Last row from List > > view, > > > > > > not the actual one which I clicked > > > > > > > Here is the Activity Class: > > > --------------------------------------------------------------------------- > > -------------------------------------- > > > > > > > public class TestListItemsView1Activity extends ListActivity { > > > > > > /** Called when the activity is first created. */ > > > > > > > private EfficientAdapter efficientAdapter; > > > > > > private static String[] data = new String[] { "BBC", > > "Yahoo", "CNN", > > > > > > "Eenadu", "Hindu" }; > > > > > > private static List<String> dataValues = > > Arrays.asList(data); > > > > > > > @Override > > > > > > public void onCreate(Bundle savedInstanceState) { > > > > > > super.onCreate(savedInstanceState); > > > > > > > requestWindowFeature(Window.FEATURE_NO_TITLE); > > > > > > setContentView(R.layout.main); > > > > > > efficientAdapter = new EfficientAdapter(this, dataValues); > > > > > > > setListAdapter(efficientAdapter); > > > > > > } > > > > > > > @Override > > > > > > protected void onListItemClick(ListView l, View v, int > > position, > > > > > > long id) { > > > > > > super.onListItemClick(l, v, position, id); > > > > > > Toast.makeText(this, "Click-" + String.valueOf(position), > > > > > > Toast.LENGTH_SHORT).show(); > > > > > > } > > > > > > > Here is the Adapter class > > > --------------------------------------------------------------------------- > > -------------------------------------- > > > > > > > public class EfficientAdapter extends BaseAdapter implements > > > > > > Filterable{ > > > > > > > private LayoutInflater mInflater; > > > > > > private Context context; > > > > > > final private List<String> data= new ArrayList<String>(); > > > > > > private HashMap<String,EfficientAdapter.ViewHolder> > > holders= new > > > > > > HashMap<String, EfficientAdapter.ViewHolder>(); > > > > > > > public EfficientAdapter(Context context,List<String> data) > > { > > > > > > //super(context, R.layout.main, values); > > > > > > mInflater = LayoutInflater.from(context); > > > > > > this.context=context; > > > > > > this.data.addAll(data); > > > > > > } > > > > > > > public View getView(final int position, View convertView, > > ViewGroup > > > > > > parent) { > > > > > > ViewHolder holder; > > > > > > > if(convertView == null){ > > > > > > convertView = > > mInflater.inflate(R.layout.adaptor_content, null); > > > > > > > holder = new ViewHolder(); > > > > > > holder.textLine = (TextView) > > > > > > convertView.findViewById(R.id.textLine); > > > > > > holder.buttonLine =(Button) > > > > > > convertView.findViewById(R.id.buttonLine); > > > holder.textLine.setText(this.data.get(position)); > > > > > > convertView.setOnClickListener(new > > OnClickListener() { > > > > > > private int pos= position; > > > > > > public void onClick(View v) { > > > > > > Toast.makeText(context, > > "Click-" + String.valueOf(pos), > > > > > > Toast.LENGTH_SHORT).show(); > > > > > > > } > > > > > > }); > > > > > > > holder.buttonLine.setOnClickListener(new > > OnClickListener() { > > > > > > private int pos= position; > > > > > > > public void onClick(View v) { > > > > > > ViewHolder deleteHolder = > > (ViewHolder)v.getTag(); > > > > > > int > > delPosition=deleteHolder.position; > > > holders.remove(delPosition); > > > > > > ViewHolder currentHolder; > > > > > > for(int > > i=pos+1;i<getCount();i++){ > > > > > > currentHolder = > > holders.get(delPosition); > > > currentHolder.position=i-1; > > > > > > } > > > > > > data.remove(delPosition); > > > > > > notifyDataSetChanged(); > > > > > > > Toast.makeText(context, > > "Delete-" + String.valueOf(pos), > > > > > > Toast.LENGTH_SHORT).show(); > > > > > > > } > > > > > > }); > > > > > > holder.position=position; > > > > > > holders.put(Integer.toString(position), > > holder); > > > > > > convertView.setTag(holder); > > > > > > > } else { > > > > > > holder =(ViewHolder) convertView.getTag(); > > > > > > } > > > > > > > return convertView; > > > > > > } > > > > > > > advance Thanx, > > > > > > Krishna > On Tuesday, March 20, 2012 7:34:00 AM UTC-7, radhakrishna wrote: > > > @seshu > > > You mean updating onListItemClick method in > > TestListItemsView1Activity : > > --------------------------------------------------------------------------- > > ------------------ > > > protected void onListItemClick(ListView l, View v, int position, > > long id) { > > super.onListItemClick(l, v, position, id); > > Toast.makeText(this, "Click-" + String.valueOf(position), > > Toast.LENGTH_SHORT).show(); > > dataValues..remove(position); > > } > > --------------------------------------------------------------------------- > > ------------------ > > > This does not work for me, I need to click remove button to remove > > listrow. > > > My ListView contains [TextView and delete Button], I need to delete > > list row, when I click on Delete button, When I click On Delete button > > it will not enter into onListItemClick method under > > TestListItemsView1Activity class , it will enter only when I select > > TextView (Text). > > > Onlick method for delete button located in EfficientAdapter class. > > > On Mar 20, 2:20 pm, Seshu <s.seshu...@gmail.com> wrote: > > > dataValues..remove(position); will deletes the entire row only... > > > > On Mar 20, 6:58 pm, radhakrishna <radhakrishna.kotako...@gmail.com> > > > wrote: > > > > > Thank you for your response Seshu, But I would like to delete list > > > > row, when I click on delete button from List view. > > > > > On Mar 20, 1:12 pm, Seshu <s.seshu...@gmail.com> wrote: > > > > > > Hi radhakrishna, > > > > > if u want to delete the list row in the list view. > > > > > > protected void onListItemClick(ListView l, View v, int position, > > > > > long id) { > > > > > super.onListItemClick(l, v, position, id); > > > > > Toast.makeText(this, "Click-" + String.valueOf(position), > > > > > Toast.LENGTH_SHORT).show(); > > > > > > dataValues..remove(position); > > > > > > } > > > > > > Thanks and > > ... > > read more » -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en