1
我目前正在使用Android的解析API,並且我目前在我的應用程序中有一個字符串數組。我目前有一個ListView與我所有的字符串。在ListView本身的應用程序內部,我實現了一個setOnItemLongClickListener
,其中Dialog
。我想從Parse中刪除選定的ListView項目的字符串。如何從解析數組中刪除字符串
NotesFragment.java
public class NotesFragment extends Fragment {
ParseUser user;
ListView notesList;
private FloatingActionButton FAB;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_notes, container, false);
notesList = (ListView) rootView.findViewById(R.id.lv_contact);
user = ParseUser.getCurrentUser();
FAB = (FloatingActionButton) rootView.findViewById(R.id.fab);
FAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), AddNoteActivity.class);
getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
startActivity(intent);
}
});
final ArrayList<ParseObject> list1 = (ArrayList) user.getList("notes");
ArrayAdapter<ParseObject> arrayAdapter;
arrayAdapter = new ArrayAdapter<ParseObject>(getContext(), android.R.layout.simple_list_item_1, list1);
RelativeLayout emptyView = (RelativeLayout) rootView.findViewById(R.id.empty);
if (list1 == null) {
emptyView.setVisibility(View.VISIBLE);
} else {
notesList.setAdapter(arrayAdapter);
emptyView.setVisibility(View.INVISIBLE);
}
notesList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
new AlertDialog.Builder(getContext())
.setTitle("Are you sure you want to Delete?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ArrayList<String> toRemove = new ArrayList<>();
toRemove.add("Hey");
ParseUser.getCurrentUser().removeAll("checklistDat", toRemove);
ParseUser.getCurrentUser().saveInBackground();
ParseUser.getCurrentUser().deleteInBackground();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
return true;
}
});
return rootView;
}
}
什麼Happe的解決這個問題NS?你看到logcat中的任何東西嗎? – Sufian