0

I'm using TwitterKit to load a list of tweets in an activity. I would like to add a custom ActionBar to my activity. I'm unable to find a way to extend both AppCompatActivity and ListActivity at the same time... Are there any workarounds or solutions for this? Please see code below

public class travel_info extends ListActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_travel_info);


        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setCustomView(R.layout.custom_line_info);
        View view = getSupportActionBar().getCustomView();


        Twitter.initialize(this);
        final UserTimeline userTimeline = new UserTimeline.Builder()
                .screenName("TfLTravelAlerts")
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
                .setTimeline(userTimeline)
                .build();
        setListAdapter(adapter);
    }
}
Edward Tattsyrup
  • 245
  • 1
  • 3
  • 15
  • the solution is to not extend ListActivity and not use a listview. Then you can extend AppCompatActivity and use a recyclerview – Tim Nov 14 '17 at 11:02
  • also please `class travel_info` use standard java naming conventions – Tim Nov 14 '17 at 11:04
  • There is no way to extend both classes which is not possible in java(Multiple inheritence).. Why you want to extend it? – Shailendra Madda Nov 14 '17 at 11:11
  • i dont think this a duplicate it is a totally diff question@TimCastelijns – Amit Vaghela Nov 14 '17 at 11:12
  • Possibly a duplicate!? However, @TimCastelijns, I change to a RecyclerView and all works great now! Thanks for pointing me in the right direction. – Edward Tattsyrup Nov 14 '17 at 11:20
  • Yes. Duplicate. The question is not 100% the same, but similar enough. Even the answers/solution are the same. @AmitVaghela you can think what you want, but you also think that saying "you can only extend a single class" is a good answer to this question – Tim Nov 14 '17 at 11:23
  • check answer first@TimCastelijns – Amit Vaghela Nov 14 '17 at 11:24

2 Answers2

-1

You can only Extend a single class. And implement Interfaces from many sources.

Extending multiple classes is not available.

you could use ListActivity or ListView inside regular Activity. In the newest versions of Android, preferred way of displaying items on a list is using so called RecyclerView.

Please, see linked documentation. It's quite good and helpful. Besides naming convetion, RecyclerView gives you more flexibility and has ViewHolder pattern implemented out-of-the-box for re-using views during the scrolling what increases application's performance. Before introducing RecyclerView, you had to implement ViewHolder pattern on your own.

Instead of Activity or ListActivity, you should use AppCompatActivity and place RecyclerView inside it to keep backward compatibility with older systems and devices.

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
-1

I'm unable to find a way to extend both AppCompatActivity and ListActivity at the same time

If you want to use ListView in your app then directly use it without extending ListActivity See here

Tim
  • 41,901
  • 18
  • 127
  • 145
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138