@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.account_settings_edit_quick_responses_fragment, container, false); final ListView listView = UiUtilities.getView(view, R.id.account_settings_quick_responses_list); final TextView emptyView = UiUtilities.getView((ViewGroup) listView.getParent(), R.id.empty_view); listView.setEmptyView(emptyView); listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Cursor c = (Cursor) listView.getItemAtPosition(position); final String quickResponseText = c.getString(c.getColumnIndex(UIProvider.QuickResponseColumns.TEXT)); final Uri uri = Utils.getValidUri( c.getString(c.getColumnIndex(UIProvider.QuickResponseColumns.URI))); EditQuickResponseDialog.newInstance(quickResponseText, uri, false) .show(getFragmentManager(), null); } }); return view; }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // startPreferencePanel launches this fragment with the right title initially, but // if the device is rotated we must set the title ourselves if (savedInstanceState != null) { getActivity().setTitle(savedInstanceState.getString(BUNDLE_KEY_ACTIVITY_TITLE)); } final SimpleCursorAdapter adapter = new SimpleCursorAdapter( getActivity(), R.layout.quick_response_item, null, new String[] {UIProvider.QuickResponseColumns.TEXT}, new int[] {R.id.quick_response_text}, 0); final ListView listView = UiUtilities.getView(getView(), R.id.account_settings_quick_responses_list); listView.setAdapter(adapter); getLoaderManager() .initLoader( 0, null, new LoaderManager.LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader( getActivity(), mAccount.quickResponseUri, UIProvider.QUICK_RESPONSE_PROJECTION, null, null, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { adapter.swapCursor(data); } @Override public void onLoaderReset(Loader<Cursor> loader) { adapter.swapCursor(null); } }); }