From 64ff9af045466fef4ed0443d0bb311781c9abba2 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 11 Feb 2016 22:41:36 -0800 Subject: Fix crash trying to long press top row of Shares dialog --- .../java/github/daneren2005/dsub/util/Util.java | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index be9536ed..435c33c0 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -1245,32 +1245,35 @@ public final class Util { } showDetailsDialog(context, context.getResources().getString(title), headerStrings, details); } - public static void showDetailsDialog(Context context, String title, List headers, List details) { + public static void showDetailsDialog(Context context, String title, List headers, final List details) { ListView listView = new ListView(context); listView.setAdapter(new DetailsAdapter(context, R.layout.details_item, headers, details)); listView.setDivider(null); listView.setScrollbarFadingEnabled(false); - // Let the user long-click on a row to copy its value to the clipboard - final Context contextRef = context; - listView.setOnItemLongClickListener(new ListView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView parent, View view, int pos, long id) { + // Let the user long-click on a row to copy its value to the clipboard + final Context contextRef = context; + listView.setOnItemLongClickListener(new ListView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView parent, View view, int pos, long id) { + TextView nameView = (TextView) view.findViewById(R.id.detail_name); + TextView detailsView = (TextView) view.findViewById(R.id.detail_value); + if(nameView == null || detailsView == null) { + return false; + } - TextView nameView = (TextView) view.findViewById(R.id.detail_name); - TextView detailsView = (TextView) view.findViewById(R.id.detail_value); - CharSequence name = nameView.getText(); - CharSequence value = detailsView.getText(); + CharSequence name = nameView.getText(); + CharSequence value = detailsView.getText(); - ClipboardManager clipboard = (ClipboardManager) contextRef.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText(name, value); - clipboard.setPrimaryClip(clip); + ClipboardManager clipboard = (ClipboardManager) contextRef.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText(name, value); + clipboard.setPrimaryClip(clip); - toast(contextRef, "Copied " + name + " to clipboard"); + toast(contextRef, "Copied " + name + " to clipboard"); - return true; - } - }); + return true; + } + }); new AlertDialog.Builder(context) // .setIcon(android.R.drawable.ic_dialog_info) -- cgit v1.2.3