0

listactivityのデータを削除するためのコンテキストメニューがありますが、アプリケーションで試したところ、データが削除されません。以前は、AlmagHelperクラスで部分文字列クエリを使用してデータを入力していました。私が作成したコーディングに何か問題がある場合はどうなりますか?助けてください ..

私が作成したこのアクティビティクラス..

public class Pendapatan extends ListActivity {
    Cursor model=null;
    AlmagAdapter adapter=null;
    AlmagtHelper helper=null;

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview_nasabah);

        helper=new AlmagtHelper(this);

        model=helper.getAllPendapatan();
        startManagingCursor(model);
        adapter=new AlmagAdapter(model);
        setListAdapter(adapter);

        registerForContextMenu(getListView());
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        getMenuInflater().inflate(R.menu.action_pendapatan, menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item){
        AdapterView.AdapterContextMenuInfo info=
            (AdapterContextMenuInfo)item.getMenuInfo();

        switch (item.getItemId()) {
        case R.id.hapus_pendapatan:
            delete(info.id);
            return(true);
        }
        return false;
    }

    private void delete(final long rowId) {
        if (rowId>0) {
            new AlertDialog.Builder(this)
            .setTitle("Hapus")
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prosesDelete(rowId);
                }
            }) .setNegativeButton("Batal", new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            }).show();
                }
    }

    private void prosesDelete(long rowId) {
        String[] args={String.valueOf(rowId)};

        //is there something wrong with this code?

        helper.getWritableDatabase().delete("pendapatan", "_id =?", args);
        model.requery();
    }

これは、AlmagHelperクラスに含まれるデータを入力するためのコードです。

public Cursor getAllPendapatan() {
    return(getReadableDatabase()
                    .rawQuery("SELECT substr(_id, 1, 10) as _id, sum(value) as total FROM pendapatan GROUP BY _id ",
                                        null));
}

このコードを使用してみましたが、機能しません

private void prosesDelete(long rowId) {
        String[] args={String.valueOf(rowId)};

        helper.getWritableDatabase().delete("pendapatan", "(substr(_id, 1, 10)) = _id =?", args);
        model.requery();
    }

私がするための解決策はありますか?どんな解決策も私にとって非常に役に立ちます。ありがとう :-)

4

1 に答える 1

0

削除後、 setListAdapter(adapter); を実行するだけです。

于 2012-11-01T05:54:37.237 に答える