Source:
public void bindView(View view, final Context context, final Cursor cursor) { view.setTag(cursor.getPosition()); TextView titleTextView = view.findViewById(R.id.note_title); TextView contentTextView = view.findViewById(R.id.note_content); ToggleButton toggleView = view.findViewById(R.id.pin_button); String title = ""; String snippet = ""; if (cursor.getColumnIndex(Note.TITLE_INDEX_NAME) > -1) { title = cursor.getString(cursor.getColumnIndex(Note.TITLE_INDEX_NAME)); } if (cursor.getColumnIndex(Note.CONTENT_PREVIEW_INDEX_NAME) > -1) { snippet = cursor.getString(cursor.getColumnIndex(Note.CONTENT_PREVIEW_INDEX_NAME)); } titleTextView.setText(title); contentTextView.setText(snippet); toggleView.setVisibility(View.GONE); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Note note = mNotesAdapter.getItem((int)view.getTag()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); preferences.edit().putString(PrefUtils.PREF_NOTE_WIDGET_NOTE + mAppWidgetId, note.getSimperiumKey()).apply(); Bundle arguments = new Bundle(); arguments.putString(NoteEditorFragment.ARG_ITEM_ID, note.getSimperiumKey()); arguments.putBoolean(NoteEditorFragment.ARG_MARKDOWN_ENABLED, note.isMarkdownEnabled()); Intent intent = new Intent(context, NoteEditorActivity.class); intent.putExtras(arguments); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, mAppWidgetId, intent, 0); mRemoteViews.setOnClickPendingIntent(R.id.widget_layout, pendingIntent); mRemoteViews.setTextViewText(R.id.widget_text, note.getTitle()); mWidgetManager.updateAppWidget(mAppWidgetId, mRemoteViews); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } }); }

Target:
public void bindView(View view, final Context context, final Cursor cursor) { view.setTag(cursor.getPosition()); TextView titleTextView = view.findViewById(R.id.note_title); TextView contentTextView = view.findViewById(R.id.note_content); ToggleButton toggleView = view.findViewById(R.id.pin_button); String title = ""; String snippet = ""; if (cursor.getColumnIndex(Note.TITLE_INDEX_NAME) > -1) { title = cursor.getString(cursor.getColumnIndex(Note.TITLE_INDEX_NAME)); } if (cursor.getColumnIndex(Note.CONTENT_PREVIEW_INDEX_NAME) > -1) { snippet = cursor.getString(cursor.getColumnIndex(Note.CONTENT_PREVIEW_INDEX_NAME)); } titleTextView.setText(title); contentTextView.setText(snippet); toggleView.setVisibility(View.GONE); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Note note = mNotesAdapter.getItem((int)view.getTag()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); preferences.edit().putString(PrefUtils.PREF_NOTE_WIDGET_NOTE + mAppWidgetId, note.getSimperiumKey()).apply(); Bundle arguments = new Bundle(); arguments.putString(NoteEditorFragment.ARG_ITEM_ID, note.getSimperiumKey()); arguments.putBoolean(NoteEditorFragment.ARG_MARKDOWN_ENABLED, note.isMarkdownEnabled()); Intent intent = new Intent(context, NoteEditorActivity.class); intent.putExtras(arguments); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, mAppWidgetId, intent, 0); mRemoteViews.setOnClickPendingIntent(R.id.widget_layout, pendingIntent); mRemoteViews.setTextViewText(R.id.widget_text, note.getTitle()); mRemoteViews.setTextColor(R.id.widget_text, getResources().getColor(R.color.gray_dark)); mWidgetManager.updateAppWidget(mAppWidgetId, mRemoteViews); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); finish(); } }); }