There is not a whole lot that you can do to access the text view. AFAIK, everything must be done through the RemoteViews object and its appropriate "set..." functions like you have here : updateViews.setTextViewText(R.id.myTxt,"Helloworld");
You can access some other functions of TextView via functions like setInt(), setDouble(), setFloat()... But I am not positive which ones are accessible in this way. On Sep 22, 9:13 am, ColletJb <[email protected]> wrote: > The problem is that findViewById() belongs to Activity, not > AppWidgetProvider. > > How could I do then ? (access myTxt field on that example) > > Example : > > public class Widget extends AppWidgetProvider > { > @Override > public void onUpdate(Context context, AppWidgetManager > appWidgetManager, > int[] appWidgetIds) { > context.startService(new Intent(context, > UpdateService.class)); > } > public static class UpdateService extends Service { > > @Override > public IBinder onBind(Intent intent) { > return null; > } > > public void onStart(Intent intent, int startId) { > RemoteViews updateViews = null; > try { > updateViews = buildUpdate(this); > } catch (Exception e) { > Log.i("INFO", e.toString()); > } > > // Push update for this widget to the home screen > ComponentName thisWidget = new ComponentName(this, > Widget.class); > AppWidgetManager manager = AppWidgetManager.getInstance > (this); > manager.updateAppWidget(thisWidget, updateViews); > } > > private RemoteViews buildUpdate(Context context) > throws Exception { > RemoteViews updateViews = null; > updateViews = new > RemoteViews(context.getPackageName(), > R.layout.widget_bg); > updateViews.setTextViewText(R.id. > myTxt,"Helloworld"); > > return updateViews; > } > > } > > } > > On 16 sep, 19:07, Jack Ha <[email protected]> wrote: > > > Try: > > > TextView tv = (TextView)findViewById(R.id.myTxt); > > > -- > > Jack Ha > > Open Source Development Center > > ・T・ ・ ・Mobile・ stick together > > The coverage you need at the price you want > > > The views, opinions and statements in this email are those of > > the author solely in their individual capacity, and do not > > necessarily represent those of T-Mobile USA, Inc. > > > On Sep 16, 5:34 am,ColletJb<[email protected]> wrote: > > > > Hi, > > > > I have already developed some widgets for android, but every time, I > > > have the same problem... I Can' access my XML layout's elements from > > > my java code. > > > > For example : > > > > <?xml version="1.0" encoding="utf-8"?> > > > <LinearLayout > > > xmlns:android="http://schemas.android.com/apk/res/android" > > > android:layout_width="fill_parent" > > > android:layout_height="fill_parent"> > > > > <TextView > > > android:id="@+id/myTxt" > > > android:Text="HelloWorld !" > > > android:layout_width="wrap_content" > > > android:layout_height="wrap_content" /> > > > > </LinearLayout> > > > > With this layout, how can I access my "myTxt" object ? > > > > Thank you for your help > > > >ColletJb > > > > PS : In an Activity, the equivalent is "findViewById(int)". > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

