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.
Related
It is kind of a general question but I noticed that I needed it multiple times and could not find an answer.
There are many cases where I needed to change a view to make it work for my specific purposes and I needed to create a custom TextView, custom EditText, custom autoCompleteTextView and so on.
Where can I find those source codes so I could use them and change them for my purposes?
Thank you
You can create new class extend from TextView or EditText and do it.
To find source codes you can with ctrl+U on class.
I am using ARToolKit nftSimple example and trying to java method when marker is detected but code is not working.
You could do it in a much easier way without touching the NDK.
The ARToolkit class has methods for querying the visibility of the markers, they are usually invoked on the Renderer, but you could as well create a thread that keeps checking them.
This is the code you need to check for marker visibility in Java:
boolean markerVisible = ARToolKit.getInstance().queryMarkerVisible(mMarkerId);
I just extended the sample arSimpleProj (the Android Studio project).
In the class org.artoolkit.ar.samples.ARSimple.SimpleRenderer
after line 104 add the following:
Intent newActivity = new Intent(activity,PlainActivity.class);
activity.startActivity(newActivity);
You need to have a Activity named PlainActivity with a corresponding layout.
I'm using Big Nerd Ranch's recyclerview-multiselect library to give my RecyclerView's CardViews a multi-selection capability. I've worked out my app-specific kinks for the most part, but I ran into a pretty big issue. Whenever the RecyclerView is in SelectionMode and has to recreate a card (which is often, because that's practically the point of RecyclerView, at least if I understand it correctly,) it throws this error:
java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.support.v7.widget.RoundRectDrawableWithShadow
at android.support.v7.widget.CardViewEclairMr1.getShadowBackground(CardViewEclairMr1.java:159)
at android.support.v7.widget.CardViewEclairMr1.getMinWidth(CardViewEclairMr1.java:150)
at android.support.v7.widget.CardView.onMeasure(CardView.java:181)
at android.view.View.measure(View.java:16498)
Logically, I followed the error to whatever source was causing a StateListDrawable to be set as the CardView's background. What I found was summed up by a commented section in this class. It reads as follows:
selectionModeBackgroundDrawable defaults to a StateListDrawable that displays your colorAccent theme color when state_activated=true, and nothing otherwise.
In the SwappingHolder class, you can see where the StateListDrawable, causing the error, is being returned. Also, if you look in the CardViewEclairMr1.java, as suggested in the error, you can see the method that most directly causes the error:
private RoundRectDrawableWithShadow getShadowBackground(CardViewDelegate cardView) {
return ((RoundRectDrawableWithShadow) cardView.getBackground());
}
To be honest, after all this snooping around in the BigNerdRanch library, I'm still not sure what to do! I was thinking I might need to #Override the BigNerdRanch methodology which brings in a StateListDrawable, but that would be getting my hands so dirty with the library, it would defeat the purpose of implementing their API to begin with. How do I fix this error?
A little late with the answer but here is something that I found and that worked for me.
Check to see if your CardView layout is wrapped inside a ViewGroup and if is not that might be the problem.
SwappingHolder works by swapping out the drawables of the top-level View. CardView uses its own drawables, so it will not work if you use it as the top-level View.
So the right way is this
<FrameLayout
...
>
<CardView
...
>
</CardView>
</FrameLayout>
Or you can implement the SelectableHolder interface yourself, and choose how you want to display a selected item.
All these are the authors words so here is a [link to GitHub][link] to the actual page
[link]:https://github.com/bignerdranch/recyclerview-multiselect/issues/14.
Good luck !
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.
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 :)