Refreshing the android widget through code. - android

I have created a Widget in android. By clicking that widget I am launching an activity, from there the user can choose any of the item displayed there in the list list view. I am storing the selected item in a shared preference. But the value the user have changed is not updating in the widget until i am re installing the widget. I want to update the widget by code. Is that possible ?

Yes, of course. Here you can find detailed simple example including the code samples: http://developer.android.com/guide/topics/appwidgets/index.html#UpdatingFromTheConfiguration

Related

How can i make widget of any ListView item?

I am working on the Note's application. In my appication i want to add the functionality like ColorNotes and Notes app. When i long click to any listview item then it should become the widget on main screen.
How can i build such functionality ?
you can use below link to Learn App Widget
https://developer.android.com/guide/topics/appwidgets/index.html
Use this Example for Sample this will help you to understand how will use list in Widget
https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget/LoremWidget
I am going to assume that those are screenshots of Android home screens, showing some app widgets.
You cannot cause an app widget to be added to the home screen. After all, not all home screens offer app widgets. The user would have to set up the app widget themselves.
Given that the user set up the app widget, you are welcome to populate it based on a long-click of a list row in one of your activities. Use AppWidgetManager and updateAppWidget() to push a new RemoteViews to the app widget based on what the user long-clicked on.

How to open activity when user will set widget on home screen?

I want to create an android widget like CNN app widget. Let me explain you the follow of widget. I set on variable on shared preference to store category value if its null than open one activity which has list to select category and than load the data according to that category in widget. I put my code on onUpdate even in widget it will load data according to the category its working fine but my problem is when i am going to set my widget i just click on it and it will open the activity after i select the category it will close category activity but widget is not set on home screen so for that i have to again to the widget menu have to pic the widget and drop on the homescreen.
so i want to open my category selection activity when user drop the widget on home screen. I google a lot but not find any solution for it. please help me out. Thank you in advance.
You need to set the configure Activity to the widgets's xml file like this:
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:configure="your.package.your.activity"
.... />
Here is the official documentation regarding this topic:
https://developer.android.com/guide/topics/appwidgets/index.html#Configuring

setting some checkbox to true by default for a custom ArrayAdapter

I am working on an Android app right now that will put shortcuts of apps onto the home screen.
I have everything working fine right now.
Currently the user is presented with a list of applications that are installed and they can multi select from the list with CheckBox's. However, I would like my application to already have some of the applications in the list checked by default when the user launches the app.
For instance, when the user first launches the application there are 3 of the apps that are selected by default ( for what ever reason, can be hard coded or in a properties file this does not matter right now ).
How can i do this? I basically need to be able to compare the name of the scanned application against a name in a properties file and if they match, check it by default. I have tried a couple ways and am lost. Can someone point me in the right direction or give me some hints here?
Getting the reference to the CheckBox associated with an item in the list from the custom ArrayAdapter seems to be my issue.
Thanks
I decided to basically create a class that would contain the information regarding the shortcuts. And in the class it had a boolean for holding on to the state of the selection of the checkbox. Basiclly using a MVC pattern.
Then i updated my getView() in my adapter. And added a method in my main activity for setting the default selected. Then added a method in my adapter to set the checked shortcuts and notifyDataSetChanged() everytime a change was made.
If anyone would like more detail, just comment here and i can add code if needed.

adding applications onto the widgets list present in home screen

Hie all ,
I am trying to create an simple application and i want that application to show in the widgets list, i.e on long press on the idle home screen it pops up a spinner for us , you can see it in the below figure,
in that you can see item called widgets which list some set of the applications, even you can see that in the next diagram.. My requirement is that i want my application to be listed there rather showing the general applications list.
thanks
datta
You need to create a widget application
see these tutorials
http://www.vogella.de/articles/AndroidWidgets/article.html

show spinner before adding widget android

For a widget I am creating for the Android OS, I want the user to first select a certain option from a Spinner. Just like when you add a shortcut to the homescreen.
Is that possible or do you have to start an Activity?
If it is possible, can anyone explain how to do it?
Spinner widgets do not exist on their own -- you have to have them in an Activity. Android's app widget framework supports the notion of a configuration activity that is automatically launched when somebody chooses your widget. Just put your Spinner in there.

Categories

Resources