I would like to use RoboActivity with my activity, but I don't know how to do that coz my current activity extends already ActionBarActivity:
public class MainActivity extends ActionBarActivity
Thank you so much
For RoboGuice 3 simply extend from RoboActionBarActivity.
You can simply copy the relevant RoboActivity parts into your subclass of ActionBarActivity. From the official docs https://github.com/roboguice/roboguice/wiki/Using-your-own-BaseActivity-with-RoboGuice:
In case your base activity class already extends a different library, the best way to get all the power of RoboGuice is to copy all the code contained in RoboActivity.
An example is also provided therein.
Related
The webpage with the following address states that the class FragmentActivity extends the class Activity:
https://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
However, when I bring up the documentation for the android.support.v4.app.FragmentActivity class within Android Studio, it states that FragmentActivity extends android.support.v4.app.BaseFragementActivityHoneycomb.
What is the reason for the discrepancy and which is correct?
This goes up to BaseFragmentActivityDonut. These base fragments are just an implementation detail of FragmentActivity and should not concern you at all. In the library I use, FragmentActivity directly extends BaseFragmentActivityJB. In the future there might be something like BaseFragmentActivityM or some compatibility layer for even newer platforms.
For your programming just assume it extends Activity only, like the documentation states.
I am new to Android and I know that we can not extends multiple classes. Please tell me how to do that? Please Correct my code.
public class Tab1 extends Fragment,ListActivity {
}
You cannot extend multiple classes in Activity or Fragment,
Like this
public class MainActivity extends AppCompatActivity, baseClass{}
So what you can do is to create a new java BaseClass file that extends AppCompatActivity. The MainActivity will extent only BaseClass, Like this
public class MainActivity extends BaseClass{} //mainactivity extents baseclass
public class BaseClass extends AppCompatActivity{}//baseclass extents appcompatactivity
The advantage is that you can implement some base functions in the BaseClass, such as Toast, checking for internet connection, etc.
Please checkout the images in case of Activity.
MainActivity extents BaseClass,
BaseClass extents AppCompatActivity
In Case of Fragments
MyFragment extents BaseFragment,
BaseFragment extents Fragment
I hope it will be helpfull, Thank you.
The short answer is that you can't. Java doesn't allow for multiple inheritance. What you can do is implement multiple interfaces. So if you want to make a Fragment that has a ListView in it you can do something like this:
public class Tab1 extends Fragment implements BaseAdapter {
}
Unfortunately JAVA does not allowed you to extends multiple classes into one class. you can use Inner class or make your 2nd class a Interface you can include multiple interface but not multiple class. Inner class would be more suitable.
I'm new to android programming how to extend two activity . In my case I'm using ActionBarActivity
im already extends the a class for some functionalities how shall i extend two activities my class
any example code will be more useful for me
This is not much of a Android problem (as Activity is class as any other), it's the way Java works.
Java doesn't support multiple inheritance, so classes can only extend one other class.
class A extends B{
}
Even in this case:
class A {
}
class A extends another class - Object - but it is automatically implied without having to specify it.
If you want to ensure some functionality from several sources you will have to use interfaces and the implements keyword:
class A extends B implements C,D,E {
}
I have created an abstract class which extends the Activity Class.
I want to extend it in an activity which extends TabActivity Class, how can I achieve that?
Get the TabActivity and abstract class Functionality at the same time.
I do realize that multiple inheritance is not possible in Java, but can I avoid extending TabActivity Class and still use getTabHost()?
10x :)
I don't think you can achieve this with this design. If your abstract class extending SomeOtherActivityClass and new Class need to extended SomeotherActivityClass (through inheritence) and TabActivityClass, that may confuse dalvik to choose which activity at runtime and it doesn't make sense. You may need to reconsider your design.
yes sure, you can use. By using following snippet:
TabHost host=(TabHost)findViewById(id of tabhost);
It's better way to create another class that extends Application class. Or use singleton pattern and create class with all functionality that you're need.
Here is the deal : I need to extends two different classes in Android.
An example:
In MainActivity.class I need to extends first TabActivity to use the tabs and getTabHost(); and in the same class I need to extends for example ListActivity or something else...How can I do that? Maybe my question is a little stupid but...
Thanks anyway!
You can extends either TabActivity or ListActivity in your main Activity.You can't extends two all together because java does not support multiple inheritence.After extending any one create the reference of another to use in your activity.
Your MainActivity doesn't need to extend TabActivity and ListActivity at the same time.
Only MainActivity needs to extend TabActivity and you can use a different Activity which extends ListActivity as the content of one or more of the tabs.
Here is the really good official documentation which has an example of what I'm talking about : http://developer.android.com/resources/tutorials/views/hello-tabwidget.html