Hello Mark,

I have been trying to implement the same functionality as Moazzam.
Specifically, I want each row in my list to have a "delete" (in my
case a process kill) button.

I read carefully your very good tutorials on lists, and tried to
follow the approach you describe in tutorial #5 (see the code below).

The result is as follows:

1) Each row does have a "kill" button
2) The first row is always blank (except for the "kill" button
3) On the "kill" button in the first row is active, i.e. performs the
required action
4) When clicking on the "kill" button in the first row, the item at
the bottom of the screen (the last visible item) is "killed"

a) I have not been able to wire all buttons
b) The button which is wired does not act on the desired item because
the value of the "position" parameter returned by getView.

I would appreciate your thoughts (or anyone else's) on this, and any
pointers regarding the errors in my code.

Thanks.

Alex Donnini

        public View getView(int position, View convertView, ViewGroup
parent) {

            ViewHolder holder;
            holder = new ViewHolder();

            try
            {
                if (convertView == null) {
                    convertView = mInflater.inflate
(R.layout.list_item_icon_text, null);

                        Button kill2 = (Button) findViewById
(R.id.kill2);
                        kill2.setOnClickListener(new
View.OnClickListener() {

                            public void onClick(View v) {

                                //Button  click action processing
                            } });

                        holder.text = (TextView)
convertView.findViewById(R.id.text);
                        holder.icon = (ImageView)
convertView.findViewById(R.id.icon);

                        convertView.setTag(holder);
                }

                else {

                    holder = (ViewHolder) convertView.getTag();

                    Button kill2 = (Button) findViewById(R.id.kill2);
                    kill2.setOnClickListener(new View.OnClickListener
() {

                        public void onClick(View v) {

                                //Button  click action processing
                        } });

                }

                holder.text.setText(activityList.get(position));
                holder.icon.setImageBitmap((position & 1) == 1 ?
mIcon1 : mIcon2);
            }

            catch(Exception e)
            {
                        e.printStackTrace();
            }

            return convertView;

        }


On Nov 2, 6:24 am, Mark Murphy <[EMAIL PROTECTED]> wrote:
> moazzamk wrote:
> > Can anyone point me in the right direction please. I used the notepad
> > example on android's site and created a listActivity which uses a
> > database to fill out thelist. However, every row has a deletebutton
> > and I want to listen for a click of thatbuttonand then delete the
> > row from listView. Is there a way I can do that?
>
> The easiest way I know of is to subclass your adapter, override
> getView(), inflate your own row Views, and attach a listener at that
> point, since you have eachButtonobject handy as part of the inflation
> process.
>
> You can get an idea of the concept by reading my "Fancy ListViews"
> series of posts over on AndroidGuys (http://androidguys.com). However,
> they were mostly from this summer and were written for the M5 SDK, and
> so will require some changes to get the source code samples to run on
> Android 1.0r1.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> _The Busy Coder's Guide to Android Development_ Version 1.3 Published!
--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to