How to combine sherlock and viewpageindicator? - android

Hey I am new in android develop.
I am now try to use both sherlock library and viewpageindicator together, but I can't.
Could you post tutorial how we combine those two ?
Thank

Below is the link which contains sample program for combining sherlock and view page indicator.
https://github.com/JakeWharton/Android-ViewPagerIndicator/
I hope you to study the full sample and analyse whole program you can understand the concept easily .
This will provide a useful information for you my friend.

You should modify Shelock Action Bar source code a little bit (change extends from Activity to FragmentActivity)
From:
public abstract class SherlockActivity extends Activity
To:
public abstract class SherlockActivity extends FragmentActivity
(for implement View Page Indicator)
And then, build Sherlock Action Bar lib again, use it like normal.

Related

How to deal with Android ActionBar code throughout the code?

I'm developing an app that has the same action bar for all Activities. The only thing that changes is the menu, which can be easily built dinamically.
At the moment, I have a xml file for each toolbar of each Activity, but there are plenty of code repetition thoughtout the code. How should I deal with it?
I've thought of making a single xml file and including it in the Activities layout. However, there are plenty of stuff that are made programatically, such as definition of the button, title and menu. These methods are located in the Activities onCreate. How is it done to reutilize this code?
Im not sure If I understand you correctly, but maybe make class which extends after Activity (or if you use AppCompatActivity etc.) for example class MyCustomActivity extends AppCompatActivity implement there your actionbar, and then in every new Activity class where you need that ActionBar just extend MyCustomActivity. In this class you can ofcourse implement some public method to set menu in subclasses etc.

Android Sliding Tabs With Material Design issue

I am creating a demo project for sliding tab with material design.
When I am doing like below :
public class MainActivity extends ActionBarActivity { // source code}
It will show red line on "ActionBarActivity". It is not allows for extends.
I have follow steps from http://www.exoguru.com/android/material-design/navigation/android-sliding-tabs-with-material-design.html
Any help would be greatly appreciated.
Since the version 22.1.0, the class ActionBarActivity is deprecated. For better approach you should use AppCompatActivity
Just change your dependency,Like :
compile "com.android.support:appcompat-v7:22.1.0"
FYI, ActionBarActivity is deprecated but it should not show red lines, that is an error indication probably due to import! Use AppCompatActivity introduced in support V7 library.

Tabbed Activity Template ActionBar.TabListener deprecated

I am using the Tabbed Activity (that includes swipes and tabs) and when I was looking at the generated code, noticed that "ActionBarActivity" is deprecated. So I went online android docs and show that I should use "AppCompatActivity" insted, I changed the extending class from ActionBarActivity to AppCompatActivity and there was no problem. However, there is another deprecated interface and that is ActionBar.TabListener. What should I use instead of this interface ?
Switch to toolbar much easier to work with you can use pagerslidingtabstrip and link it with your viewpager.

How to extend multiple Android activities

Say someone wants an Activity which both has an action bar and a preference, the first idea in mind is probably
public class MyActivity extends ActionBarActivity, PreferenceActivity
But Java doesn't allow this. I know API 11+ Activities has actionbar builtin. It's just an example of wondering how to use multiple features from multiple base classes.
EDIT: Based on the feedback it seems we have to hack in this case. IMHO it could be as simple as putting all activity utilities as fields in class Activity and implement getter/setter to use those utilities. Well, in reality, it isn't.
No you cannot extend from two classes in Java. Typically in Android to add the ActionBar to the older PreferenceActivity there are a couple of hacks you can do or libraries that also do the same thing. However, recently with the new AppCompat library they introduced the Toolbar widget which can be used to add an Actionbar to your PreferenceActivity in this case. For more information, checkout this post I recently wrote on how to add a Toolbar to your legacy SettingsActivity.
simple solution:
Firstly you can't extend multiple classes..java does not support multiple inheritance see here
Secondly using action bar sherlock library here, this gives you action bar functionality without extending the actionbaractivity plus its backwards compatiable.
Or...you can implement a custom action bar go here
As mentioned in the other answers, Java doesn't allow multiple inheritance.
If you want an ActionBar as well as something such as Preference functionality, consider using a PreferenceFragment
It's not quite the same as multiple inheritance but Fragments allow adding extra functionality to Activities.
You can create a subclass of the PreferenceActivity, called AppCompatPreferenceActivity (or whatever you would like), to use an AppCompatDelegate to provide the SupportActionBar functionality. You can then subclass the new AppCompatPreferenceActivity for your MyActivity class like so:
public class MyActivity extends AppCompatPreferenceActivity
For how to do this, check out the AppCompatPreferenceActivity sample code from the Chromium project.

ActionbarActivity class or FragmentActivity class

I want to create an activity that uses action bar ui pattern and fragments. Which base class my activity should extend, ActionbarActivity or FragmentActivity?
http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html
ActionBarActivity is the right answer
As #Pontus said, it depends on the way your requirements are:
If you are aiming API 11+ then you should go for FragmentActivity.
If you want to have your app compatible to older devices version 2.1+ then you will need the support library, ActionBarActivity.
In addition to ActionBarActivity, you have a very customized and easy to use library by Jake, ActionBar Sherlock available and its easy to implement as well. So if you wanna customize the actionbar and want it to be flexible you can even go for this.
Try and choose the best suit o your shoes. Happy Coding :)

Categories

Resources