Teju-Android / TwitterClient

Android Twitter Client App
0 stars 0 forks source link

[URGENT] ERROR with onClick method not found #1

Open teju009 opened 10 years ago

teju009 commented 10 years ago

Hi Nathan @nesquena and @thecodepath ,

I am setting a custom View to the ActionBar of the ComposeTweet activity. Its just a view and I am adding images, textview and also buttons to the view and having it on the Action Bar. Now where should I place the onClick method which the button is calling. The error is:

09-22 01:36:13.481: E/AndroidRuntime(31263): java.lang.IllegalStateException: Could not find a method onTweet(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'btTweet'

I am having the onClick in ComposeActivity, but it is not recognized.

Code is in the branch: error-onClick

nesquena commented 10 years ago

Don't use onClick XML instead attach click handler as explained here: http://stackoverflow.com/questions/11535360/how-to-detect-a-click-for-custom-action-bar

teju009 commented 10 years ago

Cool! thats so fast! Thanks so much! It worked, thanks!

Another quick question. To view the tweet in another activity, I need to add the setOnClickListener to the listView right? When I do that, how to I pass the data to the other activity? Or am I thinking wrong, should I add the onClickListener to the adapter?

nesquena commented 10 years ago

You can do setOnItemClickListener to make an item selectable and then pass the item into the intent when creating the second activity as shown here. Does that help?

teju009 commented 10 years ago

I am trying to add this listener to the view that is passed to the TweetArrayAdapter, the problem is its all working and I am displaying the wrong tweet object which is wrong. I need a way to pass the right object. The code is in https://github.com/Teju-Android/TwitterClient/blob/master/src/com/tejuapp/twitterclient/adapter/TweetArrayAdapter.java

nesquena commented 10 years ago

Ah yeah don't store Tweet at as an instance variable. Instead you need to declare Tweet "final" inside getView and it should work.

teju009 commented 10 years ago

Awesome! it worked. Thanks so much.