我有一个 ListView,我使用 JSONArray 的适配器使用自定义视图填充它。在每一行中,我都有一个删除该行的按钮,但我不知道该怎么做。
cancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder ad = new AlertDialog.Builder(context);
ad.setCancelable(false);
ad.setMessage("Are you sure?");
ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//jsonArray.remove(position);
}
});
jsonArray.remove(position)
据说undefined for the type
和_Cannot refer to a non-final variable position inside an inner class defined in a different method
我的适配器的开头是这样的:
class JSONAdapter extends BaseAdapter implements ListAdapter {
private final JSONArray jsonArray;
private final LayoutInflater mInflater;
private final Context context;
private Button pay, cancel;
public JSONAdapter(Context context, JSONArray jsonArray) {
this.jsonArray = jsonArray;
this.context = context;
mInflater = LayoutInflater.from(context);
}
那么知道如何删除它吗?提前致谢