after updating ADT i had lots of issues and deleted my Workspace and recloned everything with git and got a newer HoloEverywhere revision (dont know previous revision, but i want to use latest).
I had to check my libs in BuildPath/Order and had to fix all compiler errors (like changing imports from org.holoeverywhere.arrayadapter to org.holoeverywhere.widget.arrayadapter), and now everything except my PreferenceFragments is working again.
How i make the PreferenceFragments work again?
When i start a activity, which attaches the PreferenceFragment via
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment()).commit();
i get a blank Activity.
The PreferenceFragment is also pretty simple: only
addPreferencesFromResource(R.xml.settings);
in onCreate (i have also one with dynamic Preferences, dont work also -> not a xml problem)
anything worked before i updated ADT/HoloEverywhere
what can i do to make the PreferenceFragments work again? Logcat does not say anything special and i have also added the PreferenceFramework (as i did also before);
the problem was that android.R.id.content does not exist anylonger in the view hierarchy. i just setContentView'ed to a layout with a empty framelayout and a custom id and used that id instead of android.R.id.content.
in most tutorials it shows the method with android.R.id.content, but it seems to not be the correct way :)
Related
I am new in programming , I started learning java and worked with eclipse some time and know the very basics .
Recently I started working with android studio and I have not used any other version except the 2.2.2 for very short period , and now the newest 2.2.3 .
I am watching old tutorials and they work in activity_main , so my questions are :
1.In the newest version , should I work in the activity_main or in the content_main ?
In the activity_main the drag n drop function is not working , I can't move anything from palette to the screen to where i want (it goes directly in top left on the screen ). But in the content_main i can move once , and the second time the object puts itself in top left of the screen . How can i solve this and what is the problem ?
Also I want to ask , if you can give me some new great pdf or tutorials to learn . Thanks .
You should add code in the content_main XML file of your project. Content_main is actually the file containing the most of the UI of your MainActivity,except your navigation/toolbar. If at the beginning you are uncomfortable then instead of creating project with Blank activity, use Empty Activity shown in Figure
This will give you just only one activity_main XML file to work with. With time you will eventually understand the usage of Blank Activity as well.
I would suggest to get familiar with the different Android layouts (CoordinatorLayout as in the activity_main, LinearLayout and so on). They define how you can arrange items within the layout, so whether there are some constraints on placing items depends on the layout.
There is no overall solution, whether someone should use content_main and thus, nest layouts or just put everything into one file like e.g. activity_main.
I personally use the nesting if I use a more complex layouts like an Activity with a navigation drawer. But for an app with one activity without additional navigation I would put everything into activity_main.
For learning how to use the layouts one file might be easier instead of nesting.
Has anybody had any luck with a view pager switching between fragments that contain listviews? In particular, the listviews I am working with inflate two separate layouts to get the desired effect. However, to my understanding this is causing the viewpager to disappear as well as the tabhost. I believe this to be so because it is working with other fragments that only inflate once.
Edit 1:
I was trying to see what would happen if I used one of the fragments that showed the tabhost and used the viewpager first. I would switch views and see the correct next one. However, shortly thereafter one of the fragments that does not show the tabhost or use the viewpager, for some odd reason, would load up.
Edit 2:
It's weird it is not even loading up on the right page. It should load up on 3 but instead it loads up on 2 and replaces the former screen that was actually supposed to be there.
Adding listviews to two fragments is very easy.
In short, you want to have a main activity that's the viewpager itself. Next, the viewpager is going to host two tabs (can be as many as you want, really) which will both contain separate layouts...each with a listview of its own.
Code
The first thing we need to do is add some classes. I've made a GitHub Gist of 4 classes that I'd like you to implement into your project. You'll need to change the package name and R class to meet your project's needs.
Gist: https://gist.github.com/Andrew-Quebe/b3e9f1d0f8223ba2f8df
Second, we need to make our host activity. This is what will show the tabs and toolbar. See this next Gist as I don't want to spam up this answer with tons of code.
Gist: https://gist.github.com/Andrew-Quebe/8add2fc064397ab8efe4
You've probably gotten an error in the MainActivity.java file due to a missing ViewPagerAdapter class. That's up next!
Gist: https://gist.github.com/Andrew-Quebe/fd70ee97c2e00d72f025
And finally, the tabs that'll show our listviews!
Gist: https://gist.github.com/Andrew-Quebe/3e2a87706c98a69e7353
My apologies for taking so long in my response...I actually took the time to build all this code and error check it for you. I had an example of tabs once before but it was outdated...you weren't the only reason I made all this code. The full project can be found on GitHub here: https://github.com/Andrew-Quebe/SlidingTabsExample
Hope this helps!
Edit:
Download the sample APK to see how everything looks: https://github.com/AMQTech/SlidingTabsExample/blob/master/APKs/Sample.apk?raw=true
First of all I would like to apologize. I pointed you all in the wrong way. I did some research and as it turns out you cannot have the fragment container (frame layout) in the activity layout already. All I had to do was put the fragment container into a different layout and inflate it when the time came to switch to another fragment class and that fixed it. Thanks to everyone.
I am following some tutorials of how to make my first android app and have come across creating new activities, looking at the tutorials image of what display box I should have, it is different to what I actually have. I have installed all the latest updates for eclipse 4.4 (Luna) as well as the latest SDK and ADT plugins This is their screenshot, followed by mine:
Does anyone have any idea as to how to get the missing options of Fragment Layout Name and Navigation Type?
I have tried creating a fragment for myself and adding it to the XML file but that still returns all sorts of errors.I am following the tutorials from this place.
In the screenshot of the tutorial, they are creating a new activity by extending from MainActivity. May be the MainActivity is a tabbed Activity and it has an option to specify a Fragment and a navigation type...?
You, on the other hand are trying to create the MainActivity for the first time, but you have an issue declaring the layout file for it (the XML file holding the layout), because it already exists in your project. Do not specify it here. You can do that in code after you create the MainActivity in its onCreate method, like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
I've been having this problem a lot as well. I just figured out that the tutorial says one part wrong and that is "Select Blank Activity and click Next". You should actually select Blank Activity with Fragment. That will have the Fragment Layout Name box. http://i.imgur.com/N0ZbGL0.png Sorry, I don't have enough reputation to post images.
I have an application that works on the basic theme "Blank Activity" and what i would like to do is to change it to a "Master/Detail Flow" theme. I do know that this will make my application work on android SDK 11 + (android 3.0 Honeycomb +), that is OK with me. The issue is i don't know where to start from, what are the basic steps to make this BIG conversion? I couldn't find any example to help me out with this issue. What should i be looking for. i am sure this has been done, can you at least please give me some pointer on how to do this?
my Application is not that complicated it uses activities, async tasks, DB, custom lists,... it is very basic. I use the custom list to display data and when i click on it it displays much more details, so I thought what better way to do this in a more professorial matter than the "Master/Detail Flow". If you have any tutorial regarding the "Master/Detail Flow" that you can hook me up with that might help.
I have an application that works on the basic theme "Blank Activity"
and what i would like to do is to change it to a Master/Detail Flow"
theme.
I think a change of the application flow would be more appropriate then a change of theme. Two obvious questions that would appear are why do you suddenly want to make this change and are sure your app makes sense in a master/detail flow? The answer would most likely be positive but you should answer them nonetheless.
I do know that this will make my application work on android SDK 11 +
(android 3.0 Honeycomb +), that is OK with me
I don't see why you're app couldn't run on versions below with the new master/detail stuff.
The issue is i don't know where to start from, what are the basic
steps to make this BIG conversion? I couldn't find any example to help
me out with this issue. What should i be looking for. i am sure this
has been done, can you at least please give me some pointer on how to
do this?
You haven't provided details about how is your app implemented. The change would revolve around fragments so a BIG question would be if the current single pane version is built using the fragments framework.
If your app is built using fragments then making the change shouldn't be too hard. You'd need to:
establish which parts(fragments) should be combined in an activity(from your old ones) to make the master/detail(when the space would allow it)
change the multi pane activity to accommodate the new fragment(s). This should be easy to do but it would depend on the size of the features exposed by each of those fragments.
modify the rest of the activities(for when the app will not run in the multi pane mode), this would be small changes as the activities would mainly remain as the current version
If your app isn't built using fragments, then what I said above still applies but you'd need to also actually make the required fragments wrapping whatever functionality your app has. This would most likely result in a big code refactoring.
Here is a tutorial about the Master/Detail template in Android - An Android Master/Detail Flow Tutorial.
As far as I understand your application is up and running - so I'm not sure whether it is worth it to try rewriting it, unless you are experiencing some problems of course. :)
In general the master/details flow requires the following steps:
Implement a ListFragment showing basic information of your items
Implement a Fragment showing detailed information about a particular item
Make an xml layout file for large devices (located in layout-sw600dp folder for example). In this layout you have to put both your fragments.
Write a general version of this layout file (i.e. file with the same name but located in the layout folder), which contains only the ListFragment.
Let your activity handle onItemClick event from the ListFragment. Each time an item is clicked, you have to check if the activity is showing both fragments or only the ListFragment. If both are visible, you have to notify the details fragment that new item is selected so it can show its data. Otherwise you have to create new details fragment (you reuse it of course), pass it some information about the selected item (so it can show the item's data) and replace the ListFragment with the new one.
That a basic overview, but it should be enough to give you some idea about this flow. If you need any more details - just let me know. :)
Master/detail flow and blank activity is not same as you want to change by only changing app theme or app base theme. It will be better, if you first design master/detail flow template using UI fragments, then according integrate you blank activity with the master template making necessary changes. And for master/detail flow tutorial just google it, you will find lots of example there.
Here are some links from developer.android.com fragment-ui and adaptui
These are some guidelines about fragments but they are told using a master/Detail app.
Also dont forget to checkout the news reader app provided as sample in the second link.
If you have a recent version of the Android SDK, you should be able to create a new Android application and during that process you can elect to have the wizard create a Master/Detail Flow app for you. It will create a basic working app so that you can look through the code and understand the necessary parts.
Then, depending on how simple your app is, you may want to move all your present code to the new application or vise versa.
Macro changes that will happen:
Change all your current Activities to extend Fragment instead.
You will have to create a FragmentActivity to call your Fragments. This will basically be the boilerplate code, with just the names of your Fragments added to it.
Don't forget to double check your Manifest!
In your converted Fragments that previously extended Activity:
Everywhere you needed a Context, switch that with getActivty() (or create a global variable so that it is only called once)
Change onCreate() to
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_signals, container, false);
setHasOptionsMenu(true); // Add if you want to display a Menu
// Your initiation code here
return mView;
}
If you have a menu, change it to
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.activity_main, menu);
super.onCreateOptionsMenu(menu, inflater);
}
And that's it for basic applications. When you first change Activities to Fragments, there will be many errors. But, they are all easy to fix.
I'm trying to make a ListActivity with check boxes using one of the built in android layouts, android.R.layout.simple_list_item_multiple_choice. For background, I'm fetching the list in a private AsyncTask, then calling the adapter like this:
listActivity.setListAdapter(new ArrayAdapter<String>(listActivity,
android.R.layout.simple_list_item_multiple_choice, mDisplayList));
However when I run my code, the ListView is displayed with list_item.xml, which I'm using for all the other ListViews in my project. Any idea why this is happening?
The reason the right xml layout wasn't being used was because my AsyncTask was extending my (other) custom AsyncTask that used another xml layout and I left in this line.
super.onPostExecute();
which was at the end of the method so the inherited layout trumped the one I wanted.
When you use the android R in this way: android.R.layout... than you already have the package android before the class name R.
If you explicitly provide a class name with a complete package name, you don't need to import it, too.
That's for the case that you have the same class name from different packages which happens often when you use the android.R and your generated R class.
You don't need to import android.R.layout since you invoke it explicitely using android.R.layout.simple_list_item_multiple_choice.
That post may be of use.
Update from comment
It's hard to figure out what's the problem. Did you try to clean your project and rebuild? Sometime android int id's just do strange things if you don't clean the project and regenerate the gen files. But messing android internal references is highly unlikely… If it doesn't work, you may have another polluting setListAdapter somewhere else but it's hard to say without your full project.