Skip to content Skip to sidebar Skip to footer

How Can Get Text Of Textview That Placed On A Widget In Android Programming

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 text

Solution 1:

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.

Solution 2:

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

Solution 3:

update your code:

@OverridepublicvoidonUpdate(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=newRemoteViews(context.getPackageName(),R.layout.widgetshow);


            Intentin=newIntent(paramContext, Caller2.class); ///Activity name Caller2.class  you want to startBundlebasket=newBundle();
            TextView txt=(TextView)findViewbyId(R.id.txtid);
            Stringtest= tx.getText().toString();
            basket.putString("textViewText", test);
            in.putExtras(basket);
            PendingIntentpi= PendingIntent.getActivity(context, 0, in, 0);
            v.setOnClickPendingIntent(R.id.button, pi);
            appWidgetManager.updateAppWidget(awID, v);

        }
    }

for more help see Widget is clicked

Post a Comment for "How Can Get Text Of Textview That Placed On A Widget In Android Programming"