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