@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 <[email protected]> wrote:
> dataValues..remove(position);  will deletes the entire row only...
>
> On Mar 20, 6:58 pm, radhakrishna <[email protected]>
> 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 <[email protected]> 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 <[email protected]>
> > > 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to