0

这是代码,我认为这不会很难解决,但我已经尽我所能!:

final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                   R.layout.row, filenames);

            listView1.setAdapter(adapter);

            listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

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

                    final String item = (String) parent.getItemAtPosition(position);



                    final File a = new File(extStorageDirectory
                            + "/Android/data/com.tobin.swag/backups/" + item);

                    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

                    v.vibrate(30);

                    AlertDialog.Builder alertbox = new AlertDialog.Builder(Backups.this);

                    alertbox.setTitle("Pick a new task for " + item);
                    alertbox.setCancelable(true);
                    alertbox.setItems(array, new DialogInterface.OnClickListener() {


                        @Override
                        public void onClick(DialogInterface dialog, int which){

                            if (which == 0) {
                                Toast.makeText(getApplicationContext(), "Uploading to drive is not done, !!>?", Toast.LENGTH_SHORT).show();
                            }

                            if (which == 1) {
                                Toast.makeText(getApplicationContext(), "Copying to there is not done yet, FAR OUT !!>?", Toast.LENGTH_SHORT).show();


                            }

                            if (which == 2) {
                             a.delete();
                                adapter.notifyDataSetChanged();
                                listView1.invalidate();
                                listView1.refreshDrawableState();


                            }

我要么想删除从列表视图中单击的项目,要么只是在文件已被删除时刷新列表视图!

谢谢您的帮助!

4

2 回答 2

2

尝试在 notifyDataChange 之后调用 invalidate 方法,如下所示:

listView1.invalidateViews();
于 2013-08-22T08:21:12.117 回答
1

使用 Yourlistview.invalidateViews()。我希望它会有所帮助:)

于 2013-08-22T08:21:36.087 回答