2015-12-17 81 views
0

我使用光标显示ListView控件库和更新这种方式更新的ListView更改数据库

getSupportLoaderManager().getLoader(0).forceLoad(); 

的问题是,它不能正常工作了。当改变的方法从同一个类中调用并且不会启动任何新的意图时,ListView更新很好,否则没有什么变化。

例如,这没有任何效果

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent intent = new Intent(MainActivity.this, ItemAdd.class); 
      startActivity(intent); 
      getSupportLoaderManager().getLoader(0).forceLoad(); 
     } 
    }); 

你有什么建议,为什么它的发生?任何修复?


该问题似乎在运行更新之前,甚至发生。现在,我使用

startActivityForResult(intent, 100); 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data)   { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (resultCode == RESULT_OK && requestCode == 100) { 
     getSupportLoaderManager().getLoader(0).forceLoad(); 
    } 
} 

回答

0

让你的适配器的ListView的CursorAdapter的扩展。 然后您可以使用

notifyDataSetChanged();