在我的布局中,我有一些按钮来进行选择,然后有一个按钮来执行对数据库的查询。这个查询的结果会显示在布局内的一个
问题是,如果在执行查询后旋转屏幕,
我认为这是因为活动重新启动了。根据这里的建议,我在清单中的活动中添加了
ListView
中。问题是,如果在执行查询后旋转屏幕,
ListView
会消失,必须重新执行查询。我认为这是因为活动重新启动了。根据这里的建议,我在清单中的活动中添加了
android:configChanges="orientation|keyboardHidden"
,并在我的代码中添加了: @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.mylayout);
}
但是这不起作用。
以下是我的活动的完整代码:
public class MyClass extends ListActivity implements OnClickListener, OnCheckedChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
// Creates the buttons and setOnClickListener and setOnCheckedChangeListener
}
@Override
public void onClick(View v) {
// Manages the buttons and their functions
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// See what group in radio group is checked
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// After pressing one button, a query is made and a listview is shown.
// This it to handle the user choice after he clicks an item on the listview
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.mylayout);
}
}
这很奇怪,因为我有一些类似的活动:
public class AtoZ extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.atoz);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}
这也执行了一个查询到数据库,将其显示在ListView
上,然后处理用户的选择。如果我旋转屏幕,ListView
仍然显示。
我该怎么办?
Cursor query = baseDados.getData(1,0,null); MyAdapt cursorAdapter = new MyAdapt(this, query,0); listContent.setAdapter(cursorAdapter);
在MyAdapt
中,视图与光标绑定。 - Favolas