Back to project page Android.Parse.
The source code is released under:
MIT License
If you think the Android project Android.Parse 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.iamnbty.android.parse.fragment; //from ww w . j a v a 2s . co m import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.iamnbty.android.parse.R; import com.iamnbty.android.parse.parse.FriendParse; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback; public class AddFriendFragment extends Fragment implements View.OnClickListener { private EditText nameEditText; private EditText nickNameEditText; private Button saveButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.layout_fragment_add_friend, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // view matching nameEditText = (EditText) view.findViewById(R.id.add_friend_name_edittext); nickNameEditText = (EditText) view.findViewById(R.id.add_friend_nickname_edittext); saveButton = (Button) view.findViewById(R.id.add_friend_save_button); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); saveButton.setOnClickListener(this); } private void save(FriendParse friendParse) { Toast.makeText(getActivity(), "Saving...", Toast.LENGTH_SHORT).show(); saveButton.setEnabled(false); nameEditText.setEnabled(false); nickNameEditText.setEnabled(false); ParseObject parseObject = friendParse.toParseObject(); parseObject.saveInBackground(new SaveCallback() { @Override public void done(ParseException exception) { saveButton.setEnabled(true); nameEditText.setText(null); nickNameEditText.setText(null); nameEditText.setEnabled(true); nickNameEditText.setEnabled(true); if (exception == null) { // success Toast.makeText(getActivity(), "Save completed.", Toast.LENGTH_SHORT).show(); } else { // error Toast.makeText(getActivity(), "Save failed: " + exception.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } @Override public void onClick(View view) { if (view == saveButton) { String name = nameEditText.getText().toString(); String nickName = nickNameEditText.getText().toString(); if (name == null || name.trim().length() == 0) { Toast.makeText(getActivity(), "Please enter friend's name.", Toast.LENGTH_SHORT).show(); } else if (nickName == null || nickName.trim().length() == 0) { Toast.makeText(getActivity(), "Please enter friend's nickname.", Toast.LENGTH_SHORT).show(); } else { FriendParse friendParse = new FriendParse(); friendParse.name = name; friendParse.nickName = nickName; save(friendParse); } } } }