Back to project page PlayTogether.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project PlayTogether 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 com.rockylearnstodevelop.playtogether; /* w w w . j a va2 s. com*/ import java.util.ArrayList; import java.util.List; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import com.parse.DeleteCallback; import com.parse.FindCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.ParseQuery; import com.parse.ParseUser; public class ActivitiesFragment extends ListFragment { protected ActivityAdapter adapter; private String currentUserName; private static final String TAG = ActivitiesFragment.class.getSimpleName(); protected List<ParseObject> mActivities = new ArrayList<ParseObject>(); // List<ParseObject> sport @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_activities, container, false); return rootView; } @Override public void onResume() { super.onResume(); getActivity().setProgressBarIndeterminateVisibility(true); currentUserName = ParseUser.getCurrentUser().getUsername(); getActivity().setProgressBarIndeterminate(true); ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_SPORTACTIVITY); query.whereEqualTo(ParseConstants.KEY_USERNAME, currentUserName); //Reorder the result according to the time users shake the phone query.addDescendingOrder(ParseConstants.KEY_CREATEDAT); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> activities, ParseException e) { getActivity().setProgressBarIndeterminate(false); if(e == null){ mActivities = activities; adapter = new ActivityAdapter(getActivity(), mActivities); setListAdapter(adapter); } else{ Log.d(TAG, "No activity"); Log.d(TAG, e.getMessage()); } } }); } @Override public void onListItemClick(ListView l, View v, final int position, long id) { super.onListItemClick(l, v, position, id); final ParseObject activity = mActivities.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext()); AlertDialog dialog = builder.create(); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getActivity().getString(R.string.dialog_delete_button_label), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { mActivities.remove(position); adapter = new ActivityAdapter(getListView().getContext(), mActivities); setListAdapter(adapter); activity.deleteInBackground(new DeleteCallback() { @Override public void done(ParseException e) { if(e == null){} } }); } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, getActivity().getString(R.string.dialog_cancel_button_label), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.show(); } }