How to get text view text that fits into a widget in Android programming

I have a question. I did everything to design and code the widget before. I now have a button and a text image in my widgets. I want, when I click on my button, my text entered in the textview is added as optional for the intention, and then start this intention. I can do this with the 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 the line labeled / 100 /, I want to add the text of my text as optional. I want when I click on my button in widgets that trigger an action with the additional content of the text textview placed on the widgets that I clicked on the button.

Sorry guys for my scary english speech

+4
source share
3 answers

You do not need to get TextView text in your widget. What for? because the text of the TextView will change elsewhere, and then these changes will be applied to the widget. For example, the user can change the text in action. To show new text in widgets, you can save it in SharedPreferences and extract it into your widget.

See here for more details.

0
source

I have the same problem with you. And someone like aTa doesn't know what exactly I was expecting. And I suggest that you can use sharedPreference to save the TextView data that was placed on your Android home widget, then your activity receives data from it. This is a cheat

0
source

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 Click Widget

-2
source

Source: https://habr.com/ru/post/1401957/


All Articles