Back to project page KeepMySecret.
The source code is released under:
GNU General Public License
If you think the Android project KeepMySecret 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 keepmysecretapp.app.com.keepmysecretapp.fragments.edit; /* w w w . java 2 s .c om*/ import android.content.Intent; 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.TextView; import keepmysecretapp.app.com.keepmysecretapp.R; import keepmysecretapp.app.com.keepmysecretapp.activities.MainActivity; import keepmysecretapp.app.com.keepmysecretapp.dao.Dao; import keepmysecretapp.app.com.keepmysecretapp.dao.GroupDao; import keepmysecretapp.app.com.keepmysecretapp.db.DbContext; import keepmysecretapp.app.com.keepmysecretapp.other.Tools; import keepmysecretapp.app.com.keepmysecretapp.types.ListEntry; public class EditGroupFragment extends Fragment { private EditText groupName; private EditText groupDescribe; private Button createGroupButton; private TextView warningLabel; static ListEntry entry; public static EditGroupFragment newInstance(ListEntry entry) { /* if we want edit the group */ EditGroupFragment.entry = entry; return new EditGroupFragment(); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_edit_group, container, false); groupName = (EditText) rootView.findViewById(R.id.groupNameFieldEdit); groupDescribe = (EditText) rootView.findViewById(R.id.groupDescribeFieldEdit); warningLabel = (TextView) rootView.findViewById(R.id.groupWarningTextViewEdit); createGroupButton = (Button) rootView.findViewById(R.id.editGroupEntryButton); groupName.setText(entry.getName()); groupDescribe.setText(entry.getDescribe()); initEditButtonListener(createGroupButton); return rootView; } private void initEditButtonListener(Button button) { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (warningLabel.getVisibility() == View.VISIBLE) warningLabel.setVisibility(View.INVISIBLE); if (Tools.isStringEmpty(groupName.getText().toString())) { warningLabel.setText("??????? ???? ??????"); warningLabel.setVisibility(View.VISIBLE); return; } DbContext dbContext = DbContext.getInstance(getActivity()); Dao dao = new GroupDao(dbContext); ListEntry changedEntry = new ListEntry(); changedEntry.setID(entry.getID()); changedEntry.setName(groupName.getText().toString()); changedEntry.setDescribe(groupDescribe.getText().toString()); if (dao.read(changedEntry) != null) { warningLabel.setText("?????? ??????? ??? ????????????"); warningLabel.setVisibility(View.VISIBLE); } else { dao.update(changedEntry); Intent toMain = new Intent(getActivity(), MainActivity.class); startActivity(toMain); } } }); } }