Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get View from customised ListView?

 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,

I have a Customised ListView which contains ImageView and TextView.

I want to get instance of the TextView in onCreate().

I tried, but m getting NullPointerException….

Can anybody please help me out…..


Here’s the code m working with…






delete_list.xml





custom_list.xml





And Here’s the Java File




please help me out.....
 
pratap solapur
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should do it like this




 
pratap solapur
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should do it like this.............

 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks pratap....

i tried it but stiil m getting NullPointerException at



 
Bharath Jagdish
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where have you declared and initialized "mList" variable?
 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Bharath,

No w i corrected it,
it's mBuddyList. Declared as data member of my class DeleteActivity.
and is initialised in onCrete()

Thanks for your reply...
 
Bharath Jagdish
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt whether you can access the list items as soon as you set the adapter. Correct me if i am wrong.

Try doing operations by adding any listener to the listview.

Try checking the childcount of the list view after you set the adapter. It would be 0.
 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, we can access th child items. i achieved it by OnItemClickListener.

Here's the sample code.


 
Bharath Jagdish
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that solves the problem? Accessing the items in listeners rather than in onCreate(). Or you want that to be accessed in onCreate() only?

What i feel is, till the execution of onCreate() completes, the views wont be bound. so you will not be able to access the TextView within onCreate(). If you still want to access those variables outside the listeners, then try using Handler and post in in the queue for the thread so that onCreate() method execution is completed.

handlerInstance.post(runnableInstance);


 
Pratik Goswami
Ranch Hand
Posts: 136
Android Chrome Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prajakta,

I am facing a problem in list view, i want to add two buttons, say add and delete in list row and the same time i want to listen both button's click event with particularly list's on click event.

Here is the list design that would be look like,
+------------------------------------------+
| textview.............button1 button2 |
+------------------------------------------+
| textview.............button1 button2 |
+------------------------------------------+
I want to get click event of 1st row's button1's click event. Is it possible? In short i want to get view type on list's click event.

Thanks & Regards
Pratik Goswami
 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pratik,
first of all, it's not Prajakta, it's Prajakti....

Anyways,

I tried what you wanted to achieve but actually you can't handle Button Click events from list (I don't know the reason)

So for that i've used TextView instead of Button and the handled the events...

m attaching the files herewith for your reference....

Java File





main.xml





and test.xml




Hope it'd help you....
 
Pratik Goswami
Ranch Hand
Posts: 136
Android Chrome Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prajakta, (Sorry Prajakti :wink

Thank you very much for quick reply.

While running your given sample code i found that while clicking any button first time on a list row Toast doesn't comes up to screen. I have to click on list row fisrt and then only I am able to can get button's click event. I have to follow this procedure for all list rows. Are you getting the same problem?

Thanks & Regards
Pratik Goswami
 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes....
Because on the first click, we get View (v.findViewById())
and on the second click only we get the OnClick() event...... As far as i know, we've no option but to double click.........
 
Pratik Goswami
Ranch Hand
Posts: 136
Android Chrome Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prajakti,

Thanks for reply,

I found a thread in between to focus multiple actions/events on list. Here it is.

Thanks & Regards
Pratik Goswami
 
Joemarie Amparo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

do you have sample codes / tutorials wherein a listview will display an Image and a Text at the side of the image.


Thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic