Hi Abhishek,
what i did in my solution was not setting the onClick listener in the
getView method, but rather attach an onItemClickListener to the listview:
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int
arg2,
long arg3) {
Intent i = new Intent(act, ArticleDetail.class);
Log.d("Clicked", "args=" + arg0 + ", " + arg1 + ", " +
arg2 + ", "+arg3);
i.putExtra("articleId", messages.get((int)
arg3).getGuid());
act.startActivity(i);
}
});
where lv is a ListView object. The arg3 long is getting the position of the
view, which in my case corresponds to the position in my arraylist. So a
click on my row starts creates a new Intent and starts the activity.
This solution however is just for a ListView object as you attach an onclick
listener to the complete item of the listview. Is your objective similar of
do you need the actual buttonclick?
Regards,
Patrick
2009/12/21 Abhi <[email protected]>
> Hi Patrick,
>
> Thanks for getting back.
>
> I don't think I understand your solution completely. Maybe I am too
> exhausted to think straight.
>
> Here is what I am trying to do, I have a custom listview with an icon,
> textview and button on each row. There are 6 items in the listview and
> each row button would bring up a different activity. I want to define
> button onClick event inside my getView method to listen to the button
> clicks on each row and take necessary action. As you can see, I am
> setting the row icons under getView based on position. I want to use
> the position information to now listen to respective button clicks.
> Clueless!
>
> Would you be able to help?
>
>
> class CustomAdapter extends ArrayAdapter
> {
> CustomAdapter()
> {
> super(kis.this, R.layout.row_kis, items);
> }
>
>
> public View getView(int position, View
> convertView, ViewGroup
> parent)
> {
> LayoutInflater inflater=getLayoutInflater();
> View row=inflater.inflate(R.layout.row_kis,
> parent, false);
> TextView label=(TextView)row.findViewById
> (R.id.label);
> label.setText(items[position]);
> ImageView icon=(ImageView)row.findViewById
> (R.id.icon);
> Button row_button = (Button) findViewById
> (R.id.btlst1);
>
>
> if (items[position].compareTo("Abhi") == 0) {
>
>
> icon.setImageResource
> (R.drawable.alan); //set icon for row with name "Abhi"
>
>
> }
>
>
> ...... and so on for other rows
>
>
> }
> }
>
>
> Thanks,
>
> Abhishek
>
> On Dec 21, 4:31 pm, Patrick Plaatje <[email protected]> wrote:
> > My Apologies,
> >
> > i didn;t see the complete message thread earlier (thanx Gmail!). I hope
> my
> > post did help you though. If not, reply again and i'll see if i can help.
> >
> > Regards,
> >
> > Patrick
> >
> >
> >
> > ---------- Forwarded message ----------
> > From: Patrick Plaatje <[email protected]>
> > Date: 2009/12/21
> > Subject: Re: [android-developers] Re: button Click event inside custom
> >
> > listview.... Help!
> > To: [email protected]
> >
> > Abhishek,
> >
> > it's kinda hard to resolve this without any code, but here's how i solved
> > it:
> >
> > in the main activity, i defined the following:
> >
> > setOnItemClickListener(new OnItemClickListener() {
> > public void onItemClick(AdapterView<?> arg0, View arg1,
> int
> > arg2,
> > long arg3) {
> > Log.d(this.getClass().getSimpleName, arrayList.get((int) arg3).toString);
> > }});
> >
> > so within the onItemClickListener, i make a reference to my ArrayList and
> > show them in the log.
> >
> > Hopes it helps,
> >
> > Regards,
> >
> > Patrick
> >
> > 2009/12/21 Abhi <[email protected]>
> >
> > That didn't help..... :(
> >
> > > Can someone guide me to the right tutorial/sample code?
> >
> > > Thanks,
> >
> > > Abhishek
> >
> > > On Dec 18, 11:03 pm, android09 <[email protected]> wrote:
> > > > Hi Abhishek,
> >
> > > > You can to through the below example for creatingcustomview. Follow
> > > > the below link.
> >
> > > >http://www.anddev.org/basic_drag_and_drop-t3095.html
> >
> > > > I hope you will get the something from the above example.
> >
> > > > Best Luck.
> > > > Thanks.
> >
> > > > On Dec 18, 7:47 am, Abhi <[email protected]> wrote:
> >
> > > > > Hi guys,
> >
> > > > > I have my owncustomadapter to create acustomlistviewwith
> > > > > checkbox, textview and button in each row. I want to implement
> onClick
> > > > > on Button and take different action based on which row button is
> > > > > pressed. How can I use onClickListener in this case? Define it
> inside
> > > > > getView? If so how?
> >
> > > > > Thanks
> >
> > > > > Abhishek- Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > --
> > > 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]<android-developers%[email protected]>
> <android-developers%2bunsubsÂ[email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
> >
> > --
> > Met vriendelijke groet,
> >
> > Patrick Plaatje
> >
> > NDC|VBK de uitgevers
> > Sixmastraat 32, 8915 PA Leeuwarden
> > Postbus 394, 8901 BD Leeuwarden
> > T (058) - 284 5044
> > M (06) - 158 966 34
> >
> > --
> > Met vriendelijke groet,
> >
> > Patrick Plaatje
> >
> > NDC|VBK de uitgevers
> > Sixmastraat 32, 8915 PA Leeuwarden
> > Postbus 394, 8901 BD Leeuwarden
> > T (058) - 284 5044
> > M (06) - 158 966 34- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
Met vriendelijke groet,
Patrick Plaatje
NDC|VBK de uitgevers
Sixmastraat 32, 8915 PA Leeuwarden
Postbus 394, 8901 BD Leeuwarden
T (058) - 284 5044
M (06) - 158 966 34
--
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