Back to project page TodoList.
The source code is released under:
Apache License
If you think the Android project TodoList listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package lyc.app.fragment; /* w w w . j a va 2s .c om*/ import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; import lyc.app.App; import lyc.app.R; import lyc.app.adapter.TodoCursorAdapter; import static lyc.app.App.Todo.ACTUAL_FINISHED_DATE_SORT_ORDER; import static lyc.app.App.Todo.COLUMN_STATUS; import static lyc.app.App.Todo.CONTENT_URI; /** * Created by ivan on 14-10-24. */ public class FinishedTodoFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { private static final String TAG = "FinishedTodoFragment"; private TextView tipsTextView; private ListView myListView; private TodoCursorAdapter adapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.todo_fragment, container, false); tipsTextView = (TextView) view.findViewById(R.id.tips); tipsTextView.setText(R.string.tips_no_data_for_finished); myListView = (ListView) view.findViewById(R.id.myListView); adapter = new TodoCursorAdapter(getActivity(), R.layout.todo_item_layout, null); myListView.setAdapter(adapter); registerForContextMenu(myListView); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.d(TAG, "-----------"); if (getArguments() != null) { boolean isRefresh = getArguments().getBoolean("is_refresh"); if (isRefresh) { getActivity().getSupportLoaderManager().restartLoader(1, null, this); } } else { getActivity().getSupportLoaderManager().initLoader(1, null, this); } } @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader(getActivity(), CONTENT_URI, null, COLUMN_STATUS + " = ?", new String[]{String.valueOf(App.Todo.STATUS_FINISHED)}, ACTUAL_FINISHED_DATE_SORT_ORDER); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data.getCount() > 0) { myListView.setVisibility(View.VISIBLE); tipsTextView.setVisibility(View.GONE); } else { myListView.setVisibility(View.GONE); tipsTextView.setVisibility(View.VISIBLE); } adapter.changeCursor(data); } @Override public void onLoaderReset(Loader<Cursor> loader) { adapter.changeCursor(null); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle(R.string.remove_dialog_title); menu.add(0, 0, 0, R.string.button_positive_label); menu.add(0, 1, 1, R.string.button_negative_label); } @Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case 0: removeTodo(info.id); return true; case 1: return true; default: return super.onContextItemSelected(item); } } private void removeTodo(long id) { int count = getActivity().getContentResolver().delete(App.Todo.CONTENT_URI, App.Todo._ID + " = ?", new String[]{String.valueOf(id)}); if (count > 0) { getActivity().getSupportLoaderManager().restartLoader(1, null, this); } } }