Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从listview重新加载活动以更新数据库信息?_Android_Database_Listview_Return_Reload - Fatal编程技术网

Android 如何从listview重新加载活动以更新数据库信息?

Android 如何从listview重新加载活动以更新数据库信息?,android,database,listview,return,reload,Android,Database,Listview,Return,Reload,我正在尝试实现如下内容: 我有一个带有布局的主类,从中我从数据库中获取一些数据,并按照图中所示进行打印(带有另一个布局复杂列表): 我有一个类来实现BaseAdapter: class listAdapter extends BaseAdapter { public View getView(final int position, View convertView, final ViewGroup parent) { inflater = (LayoutInflater) conte

我正在尝试实现如下内容:

我有一个带有布局的主类,从中我从数据库中获取一些数据,并按照图中所示进行打印(带有另一个布局复杂列表):

我有一个类来实现BaseAdapter:

class listAdapter extends BaseAdapter {
public View getView(final int position, View convertView, final ViewGroup parent) {

    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
    View row;
    row = inflater.inflate(R.layout.complex_list, parent, false);
    ...
Delete = (Button) row.findViewById(R.id.delete_entry_list);
...
    Delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteEntry(id[position]);
            Intent refresh = new Intent(context, main_class.class);
            refresh.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //I've added this line because otherwise I get an error an the app crashes.
            context.startActivity(refresh);
            //((Activity)context).finish();
        }
    });
    return (row);
}
public void deleteEntry (  int id){
    DatabaseHelper myDB = new DatabaseHelper(context);
    myDB.deleteData(Integer.toString(id));
}
我试图做的是在按下delete按钮查看数据库的更新版本后刷新整个活动

我写的东西确实有用,但当我按下手机上的返回按钮时,它会返回到数据库的旧图像,而不是进入我访问此活动的菜单

我一直在研究类似的问题,我发现唯一的解决办法是添加一行注释:

//((Activity)context).finish();
但这会使我的应用程序崩溃,并出现以下错误:

java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity
谁能告诉我我做错了什么,或者有没有更简单的方法

ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity
可能是从

list.setAdapter(new listAdapter(..., this.getBaseContext()));

您应该使用
this
代替
this.getBaseContext()
,因为
活动扩展了上下文

this.getBaseContext()
替换为
this
。一个活动已经是一个上下文谢谢,这就是问题所在。现在它工作正常了。
list.setAdapter(new listAdapter(..., this.getBaseContext()));