Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void refreshScreen_SimpleWay() {
- Call<List<Section>> call = restClient.getService().getSectionsByCourseId(_Course_Id);
- call.enqueue(new Callback<List<Section>>() {
- @Override
- public void onResponse(Call<List<Section>> call, Response<List<Section>> response) {
- final ListView lv = (ListView) findViewById(R.id.listView);
- final ArrayList<HashMap<String, String>> sectionList = new ArrayList<HashMap<String, String>>();
- for (int i = 0; i < response.body().size(); i++) {
- HashMap<String, String> section = new HashMap<String, String>();
- section.put("id", String.valueOf(response.body().get(i).getId()));
- section.put("name", String.valueOf(response.body().get(i).getName()));
- sectionList.add(section);
- }
- final ListAdapter adapter = new SimpleAdapter(CourseManagerActivity.this, sectionList, R.layout.view_user_entry,
- new String[]{"id", "name"}, new int[]{R.id.user_Id, R.id.user_name});
- lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
- @Override
- public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) {
- final TextView tvName = view.findViewById(R.id.user_name);
- TextView tvId = view.findViewById(R.id.user_Id);
- _Course_Id = tvId.getText().toString();
- AlertDialog.Builder ad;
- String title = "Вы действительно хотите удалить '" + tvName.getText() + "'?";
- String message = "Удалить?";
- String button1String = "Да";
- String button2String = "Нет";
- ad = new AlertDialog.Builder(CourseManagerActivity.this);
- ad.setMessage(title); // сообщение
- ad.setPositiveButton(button1String, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int arg1) {
- System.out.println("_Course_Id:::: " + _Course_Id);
- Call<Void> call = restClient.getService().deleteSectionAndChildrenById(_Course_Id);
- call.enqueue(new Callback<Void>() {
- @Override
- public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> response) {
- if (response.code() == 200) {
- Toast.makeText(CourseManagerActivity.this, tvName.getText() + " успешно удален!",
- Toast.LENGTH_LONG).show();
- refreshScreen_SimpleWay();
- }
- else {
- Toast.makeText(CourseManagerActivity.this, "Error: Not Deleted" + response.errorBody(), Toast.LENGTH_LONG).show();
- }
- }
- @Override
- public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
- Toast.makeText(CourseManagerActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
- }
- });
- }
- });
- ad.setNegativeButton(button2String, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int arg1) {
- Toast.makeText(CourseManagerActivity.this, "Отмена", Toast.LENGTH_LONG).show();
- }
- });
- ad.setCancelable(true);
- ad.setOnCancelListener(new DialogInterface.OnCancelListener() {
- public void onCancel(DialogInterface dialog) {
- Toast.makeText(CourseManagerActivity.this, "Отмена", Toast.LENGTH_LONG).show();
- }
- });
- ad.show();
- return true;
- }
- });
- lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- tvSection_Id = (TextView) view.findViewById(R.id.user_Id);
- String sectionId = tvSection_Id.getText().toString();
- section_name = (TextView) view.findViewById(R.id.user_name);
- String sectionName = section_name.getText().toString();
- Intent objIndent = new Intent(CourseManagerActivity.this, SectionManagerActivity.class);
- objIndent.putExtra("section_Id", sectionId);
- objIndent.putExtra("section_title", sectionName);
- startActivity(objIndent);
- }
- });
- lv.setAdapter(adapter);
- }
- @Override
- public void onFailure(@NonNull Call<List<Section>> call, @NonNull Throwable t) {
- Toast.makeText(CourseManagerActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
- }
- }
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement