How to access View from AppWidgetProvider

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to access View from AppWidgetProvider

Postby colletjb » Tue Aug 25, 2009 11:37 am

Hi,

I'm trying to develop a new Android Widget.

I need to access the widget's view to edit it.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Widget extends AppWidgetProvider
  3.  
  4. {
  5.  
  6.    (...)
  7.  
  8.    public void onStart(Intent intent, int startId) {
  9.  
  10.       TextView t = ... ;
  11.  
  12.       (...)
  13.  
  14.       LinearLayout myView = findViewById("line1"); // Doesn't exist <img src="http://www.anddev.org/images/smilies/sad.png" alt=":(" title="Sad" />
  15.  
  16.       myView.addChild(t);
  17.  
  18.       (...)
  19.  
  20.    }
  21.  
  22. }
  23.  
  24.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


How to access "myView::View" object??

Thanks for your help.
colletjb
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Aug 23, 2009 8:55 am

Top

Postby nabil » Wed Aug 26, 2009 3:46 pm

Hi,

I don't know if this gonna help, but try to use RemoteViews in onUpdate method instead ...

I don't think that you can add a chid (TextView) this way ...
I suggest that you build your TextView in the WidgetLayout then you can hide it or show it.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  2.         final int N = appWidgetIds.length;
  3.  
  4.         // Perform this loop procedure for each App Widget that belongs to this provider
  5.         for (int i=0; i<N; i++) {
  6.             int appWidgetId = appWidgetIds[i];
  7.  
  8.             // Get the layout for the App Widget
  9.             RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.your_widget_provider);
  10.                        
  11.                         views.setViewVisibility(R.id.your_txt_view, View.VISIBLE);//or View.INVISIBLE, or View.GONE
  12.                        
  13.             // Tell the AppWidgetManager to perform an update on the current App Widget
  14.             appWidgetManager.updateAppWidget(appWidgetId, views);
  15.         }
  16.                
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Nabil.
nabil
Freshman
Freshman
 
Posts: 3
Joined: Wed Aug 26, 2009 3:16 pm

Postby colletjb » Wed Aug 26, 2009 4:50 pm

This is a good idea. It works if I create a lot more TextView than needed, then set the unused ones to Invisible.

That way, it works !

Thanks a lot
colletjb
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Aug 23, 2009 8:55 am

Postby dryale » Sat Sep 12, 2009 6:25 pm

I'm trying to access a TextView's text from within an AppWidgetProvider's onReceive event. Is this possible. AppWidgetProvider's don't have a FindViewByID method, nor does it seem you can access a "View" through a RemoteView instance. Am I going about this the wrong way? If I Bing AppWidgetProvider and TextView, the results are very few, and don't apply to what I'm trying to do. I'm thinking this is an incorrect approach.
dryale
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Sep 11, 2009 11:08 pm

Postby colletjb » Mon Sep 14, 2009 9:38 am

I'm quite sure it is possible...

But I didn't find the solution yet.

Maybe looking into the AppWidgetHostView object would be an idea...
colletjb
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Aug 23, 2009 8:55 am

Postby MimerPlusPlus » Tue Oct 27, 2009 12:41 pm

Has anyone found a solution to this problem? I've looked at how the GoogleSearch widget does the trick, but that seems to be a no-go for my widget.

/Dennis
MimerPlusPlus
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Oct 27, 2009 12:37 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests