删除解析服务器中的一行?

时间:2018-06-18 03:55:41

标签: java android parse-server

问题是单击它的列表项没有被删除但是它后面或前面的项被删除(对于list2.get(d)或list2.get(d-1))如何获取单击要删除的项目?)

 Intent intent=getIntent();
    k=intent.getStringExtra("this is a");
    list=(ListView)findViewById(R.id.listview);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            d=i;
            AlertDialog.Builder dialog=new AlertDialog.Builder(Main3Activity.this);
            dialog.setMessage("this is a");
            dialog.setPositiveButton("yes", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int l){
                    ParseQuery<ParseObject> b=new ParseQuery<ParseObject>("message");
                    b.findInBackground(new FindCallback<ParseObject>() {
                        @Override
                        public void done(List<ParseObject> objects, ParseException e)
                        {
                            if(e==null) {
                                for (ParseObject n : objects) {
                                    if (n.getString("message").equals(list2.get(d))&&(n.getString("receiver").equals(ParseUser.getCurrentUser().getUsername().toString())&&n.getString("sender").equals(k)))
                                    {
                                        try {
                                            Toast.makeText(Main3Activity.this,list2.get(d+1), Toast.LENGTH_SHORT).show();
                                            n.delete();
                                        } catch (Exception e1) {
                                            e1.printStackTrace();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Log.i("this is a",e.getMessage());
                            }
                        }
                    });
                    list2.remove(d);
                    a.notifyDataSetChanged();

1 个答案:

答案 0 :(得分:0)

在这种情况下,

this指的是onItemClickListener上下文。您可以通过调用getApplicationContext()使用应用程序上下文,或者如果需要本地上下文,请使用CLASSNAME.this

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Intent intent=getIntent();
list=(ListView)findViewById(R.id.listview);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        AlertDialog.Builder dialog=new AlertDialog.Builder(getApplicationContext());

    }
});

OR

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Intent intent=getIntent();
list=(ListView)findViewById(R.id.listview);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);

    }
});