1

I'm trying to build an app in android studio which displays a list of tweets from a user in a list view, and then the user can select one and the tweet text is carried forward to another activity.

I have used the following code to set an onitemclicklistener with a manually typed string array, and it worked perfectly:

final Intent i = new Intent(this, ResultsActivity.class);

myListView.setOnItemClickListener(
            new AdapterView.OnItemClickListener(){
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    String tweet = String.valueOf(parent.getItemAtPosition(position));
                    i.putExtra("tweetMessage", tweet);
                    startActivity(i);
                }
            }

    );

But now that I have used Twitter Kit's TweetUI Show Timelines function to show a list of tweets from user, I am no longer able to set an onclick listener. When I click on a Tweet, it opens the web browser and shows that Tweet on Twitter's site.

I seem to be unable to target the list view as I did before with "myListView.setOnItemClickListener", as the listview is called android::list which appears to be a name required by TwitterUI. I have set up the activity using the following code, which makes no mention of the listview name so I presume this is built into TwitterUI:

final UserTimeline userTimeline = new UserTimeline.Builder()
            .screenName("antijokes")
            .build();
    final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
            .setTimeline(userTimeline)
            .build();
    setListAdapter(adapter);

Does anyone know if there is a way to set up an onitemclick listener to the listview? TIA

J.M
  • 43
  • 8

1 Answers1

0

Try setting action callback on adapter

setOnActionCallback(Callback actionCallback) Sets the callback to call when a Tweet action is performed on a Tweet view.

    final UserTimeline userTimeline = new UserTimeline.Builder()
                                        .screenName(userName)
                                        .maxItemsPerRequest(5)
                                        .build();
    Callback<Tweet> actionCallback = new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {}

        @Override
        public void failure(TwitterException exception) {}
    };
    final TweetTimelineRecyclerViewAdapter adapter =
            new TweetTimelineRecyclerViewAdapter.Builder(getActivity())
                    .setTimeline(userTimeline)
                    .setViewStyle(R.style.tw__TweetLightWithActionsStyle)
                    .setOnActionCallback(actionCallback)
                    .build();
random
  • 10,238
  • 8
  • 57
  • 101