@Override public void onDialogPositiveClick(DialogFragment dialog) { Dialog dialogView = dialog.getDialog(); String stringName = ((EditText) dialogView.findViewById(R.id.dialog_store_name)).getText().toString(); if (editIndex == -1) { if (!stringName.isEmpty()) { Store store = new Store(stringName); long rowId = mStoreDbAdapter.insertStore(store); store.setId(rowId); mStoreList.add(store); } } else { mStoreList.get(editIndex).setName(stringName); mStoreDbAdapter.updateStore(mStoreList.get(editIndex)); editIndex = -1; } if (!stringName.isEmpty()) { mStoreAdaptor.notifyDataSetChanged(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { String stringName; super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case Constants.RESULT_SPEECH_OUTPUT: if (resultCode == RESULT_OK && data != null) { ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); stringName = text.get(0); if (stringName != null && !stringName.isEmpty()) { Store store = new Store(stringName); long rowId = mStoreDbAdapter.insertStore(store); Log.d(LOG_TAG, "Insert ret val: " + rowId); store.setId(rowId); mStoreList.add(store); mStoreAdaptor.notifyDataSetChanged(); } } break; default: Log.w(LOG_TAG, "Not handled speech resultCode"); break; } }