当前位置: 代码迷 >> Android >> Android
  详细解决方案

Android

热度:90   发布时间:2016-05-01 21:40:57.0
Android求助
我写了一个Listview如下:
  ListView shourulv = (ListView) findViewById(R.id.shourulv);
  List<HashMap<String, Object>> data1 = new ArrayList<HashMap<String, Object>>();
  for (Outcome outcome1 : outcomes)
  {
  HashMap<String, Object> item1 = new HashMap<String, Object>();
  item1.put("outcomeid", outcome1.getOutcomeid());
  item1.put("name1", outcome1.getName1());
  item1.put("money1", outcome1.getMoney1());
  item1.put("message1", outcome1.getMessage1());
  item1.put("time1", outcome1.getTime1());
  data1.add(item1);
  }
  // 适配器的选择
  SimpleAdapter adapter = new SimpleAdapter(MingxiActivity.this, data1, R.layout.item, new String[]
  { "outcomeid", "name1", "money1", "message1", "time1" }, new int[]
  { R.id.iditem, R.id.namesr, R.id.moneysr, R.id.messagesr, R.id.timesr });
  shourulv.setAdapter(adapter);
  // 为ListView添加点击事件
  shourulv.setOnItemClickListener(new OnItemClickListener
  {
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  {
  ListView lView = (ListView) parent
  HashMap<String, Object> item3 = (HashMap<String, Object>) lView.getItemAtPosition(position);

  String a=Stirng.valueOf(item3.get(outcomeid));

  dialog(a);

  }
  });
   

对话框如下:

 protected void dialog1(final Integer outcomeid5)
 {

 AlertDialog.Builder builder = new Builder(MingxiActivity.this);
 builder.setMessage("你选择的是?");
 builder.setTitle("欢迎");
 builder.setPositiveButton("删除", new
 android.content.DialogInterface.OnClickListener()
 {
 @Override
 public void onClick(DialogInterface dialog, int which)
 {

 dialog.dismiss();
 outcometable.delete(outcomeid5);

 }
 });
 builder.setNegativeButton("修改", new
 android.content.DialogInterface.OnClickListener()
 {
 @Override
 public void onClick(DialogInterface dialog, int which)
 {
 dialog.dismiss();

 }
 });
 builder.create().show();
 }



删除数据方法如下:

 public void delete(String id )
 {
  SQLiteDatabase db = financialManagementSystemData.getWritableDatabase();
  db.execSQL("delete from outcome where outcomeid=? ", new Object[]
  { id.toString()});
 }



问题是我点击删除按钮时出错了,请问问题出现在哪里?




------解决方案--------------------
报什么错了?把异常信息贴出来?
------解决方案--------------------
dialog.dismiss();//删掉
 outcometable.delete(outcomeid5);
------解决方案--------------------
不把异常公布出来谁知道是哪里错误啊
------解决方案--------------------
SimpleAdapter可以用自定义id?
可以参照这个帖子,可以帮到你。
  相关解决方案