Open maygupta opened 9 years ago
@maygupta If your item layout has a focusable or clickable element, your ListView OnItemClickListener will not be invoked since the click will be intercepted by the TextView. The solution is to add your item click handler to the custom adapter.
@nidhi1608 Thanks Nidhi. I followed the following approach and it worked fine. http://stackoverflow.com/questions/26980204/listview-with-textview-autolink-not-receiving-onitemclicklistener
Regarding binding on click event with adapter, 1) I want to bind the on click event inside Timeline activity as I need to start another activity and create Intent etc. And I don't see their a direct onItemClick method in adapter like we see for ListView.
2) I can set the onClick in adapter when laying out the view in the getView() method and then add a callback to call a method in activity like this, but its little messy approach:
class CustomerAdapter
{
CallbackHandler callbackHandler;
getView() {
tv.onClick(
callbackHandler.clicked(Item);
)
}
Is there some other way that I am missing ?
First approach is probably the most cleaner here. Another way is to set the listener on the convertView object. Check out this article for more details.
convertView.setOnClickListener(new OnClickListener() {
...
}
Ok agreed but the issue with this approach is I have to invoke a new activity when Item is clicked. Can I do that here inside adapter ? If not I will need to have a callback to Parent Activity where this adapter is initialized.
You can use getContext() to start a new activity from inside the adapter. This is a common pattern and you won't be required to have a callback.
:+1: Excellent work, again! Great to see you put in the effort to turn in a polished assignment.. A few notes after checking out the code:
Utils
class instead of model.SwipeRefreshLayout
for easy timeline refreshesActiveAndroid
annotations to the models for offline usageHere's a detailed Project 3 Feedback Guide here which covers the most common issues with this submitted project. Read through the feedback guide point-by-point to determine how you could improve your submission.
Let us know if you have any other thoughts or questions about this assignment. Hopefully by now you feel pretty comfortable with all the major pieces to basic Android apps (Views, Controllers, ActionBar, Navigation, Models, Authentication, API Communication, Persistence, et al) and see how they all fit together. We are close now to a turning point in the course where you should be hitting a "critical mass" towards your knowledge of Android.
My app is ready for review /cc @codepathreview @codepath
I had one thing to mention, when we add auto_link=all then item is no more clickable and i can't open the detailed view of the tweet. So I removed auto_link on home time line but added it in the tweet detail view.