5

i have a question. i did all things for design and coding a widget before. now i have a button and a textview in my widget. i want when i click on my button my text entered in textview puted as extra for an intent and then start that intent. i can do this with following code in :

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        for (int i=0;i<appWidgetIds.length;i++){
            int awID=appWidgetIds[i];
            RemoteViews v=new RemoteViews(context.getPackageName(),R.layout.widgetshow);
.
.
.

            Intent in = new Intent("my.app.NOTEEDITOR");
            Bundle basket = new Bundle();
        */100*/ basket.putString("textViewText", "test");
            in.putExtras(basket);
            PendingIntent pi = PendingIntent.getActivity(context, 0, in, 0);
            v.setOnClickPendingIntent(R.id.button, pi);

            appWidgetManager.updateAppWidget(awID, v);
.
.
.
        }
    }

but in line marked /100/ i want put my textviews' text as extra. i want when i click on my button in the widget that start a activity with an extra contained text of textview placed on widget that i clicked on it's button.

sorry guys for my terrible english speaking

aTa
  • 641
  • 2
  • 8
  • 20
  • possible duplicate of [get text of a TextView in android home widget (not in activity)?](http://stackoverflow.com/questions/11237217/get-text-of-a-textview-in-android-home-widget-not-in-activity) – Amir Latifi May 28 '15 at 01:20

3 Answers3

0

I have the same problem with you. And someone like aTa don't know what is my expected things exactly. And i suggest you that you can use sharedPreference to save data of TextView that placed on you android home widget, then your activity get data from it. This is a cheat

Kiradev
  • 347
  • 2
  • 17
0

You don't need to get the TextView's text in your widget. why? because the TextView's text will change in another place and then this changes will apply to widget. For example, the user can change the text in a activity. For showing the new text in widget, you can save it in a SharedPreferences and fetch it in your widget.

Refer to here for more details.

Community
  • 1
  • 1
Mbt925
  • 1,317
  • 1
  • 16
  • 31
  • thank u for ur answer. but your refrences is not about my problem. i in widget i dont now what is the text of textview then put in extra and next into intent. my textof textview is dynamic and i dont know at this time what is showing in textview on widget – aTa Mar 18 '12 at 07:02
  • i must get text from the textview and then put it into intent – aTa Mar 18 '12 at 07:04
  • I think you're wrong. The text in your TextView come from somewhere else. how don't you can know about the text on the widget? In all the widgets i saw before, the text changed in an activity and then apply to the widget. – Mbt925 Mar 18 '12 at 14:36
-2

update your code:

@Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        for (int i=0;i<appWidgetIds.length;i++){
            int awID=appWidgetIds[i];
            RemoteViews v=new RemoteViews(context.getPackageName(),R.layout.widgetshow);


            Intent in = new Intent(paramContext, Caller2.class); ///Activity name Caller2.class  you want to start
            Bundle basket = new Bundle();
            TextView txt=(TextView)findViewbyId(R.id.txtid);
            String test = tx.getText().toString();
            basket.putString("textViewText", test);
            in.putExtras(basket);
            PendingIntent pi = PendingIntent.getActivity(context, 0, in, 0);
            v.setOnClickPendingIntent(R.id.button, pi);
            appWidgetManager.updateAppWidget(awID, v);

        }
    }

for more help see Widget is clicked

Community
  • 1
  • 1
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • tnx imrankhan. i use this code before but when i user findViewById it's didn't detect this method! – aTa Mar 17 '12 at 08:24