0
listactivity에서 데이터를 삭제할 수있는 상황에 맞는 메뉴가 있지만 응용 프로그램에서 데이터를 삭제하려고해도 데이터가 삭제되지 않습니다. 이전에는 AlmagHelper 클래스에서 부분 문자열 쿼리를 사용하여 데이터를 입력했습니다. 내가 만든 코딩에 문제가 있다면? 도와주세요은 ..listactivity의 contextmenu가있는 부분 문자열 삭제
내가 만든이 활동 클래스 ..
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();
}
저에게 어떤 해결책이 있습니까? 그래? 모든 솔루션은 나를 위해 매우 유용 할 것입니다. 고마워요 :-)
답변을 주셔서 감사하지만 여전히 작동하지 않습니다. 어디 setListAdaper (어댑터) 배치? prosesDelete에 있든 없습니까? –