0
  public void AddCustomEvent() {
        ListView lv = (ListView) findViewById(R.id.listView1);


        final Set<String> tasks = sp.getStringSet("tasks", new HashSet<String>());

        ArrayList<String> taskarr = new ArrayList<String>();

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                Log.i("Hello!", String.valueOf(position) + " " + String.valueOf(id));

                final int pos = position;
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        getApplicationContext());

                // set title
                alertDialogBuilder.setTitle("Do you want to delete this task");

                // set dialog message
                alertDialogBuilder
                        .setMessage("Click yes to delete !")
                        .setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // if this button is clicked, close
                                // current activity


                                Set<String> tasks = sp.getStringSet("tasks", new HashSet<String>());

                                final ListView listview = (ListView) findViewById(R.id.listView1);

                                final ArrayList<String> list = new ArrayList<String>();
                                for (String str : tasks) {
                                    list.add(str);
                                }
                                list.remove(pos);

                                Set<String> newTasks = new HashSet<String>();

                                for (String str : list) {
                                    newTasks.add(str);
                                }

                                Editor edit = sp.edit();

                                edit.putStringSet("tasks", newTasks);

                                edit.commit();

                                final StableArrayAdapter adapter = new StableArrayAdapter(getApplicationContext(),
                                        android.R.layout.simple_list_item_1, list);

                                listview.setAdapter(adapter);

                            }
                        })
                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // if this button is clicked, just close
                                // the dialog box and do nothing
                                dialog.cancel();
                            }
                        });

                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();


            }

        });
    }

我制作了一个任务应用程序。它在删除任务之前显示警报对话框。没什么特别的。我的代码因为崩溃(我想在其中显示警报对话框)而被破坏。

有人检查代码,让我知道我如何以及在哪里泄漏服务。

http://pastebin.com/edsS9CQh

4

1 回答 1

0

堆栈跟踪中没有提到你的类。除非您实际上正在使用包名称(如 :com.android.emailcommon.utility)编写应用程序。但我想你不会在这里问问题:)

于 2013-05-28T06:22:29.063 回答