我有一個XML佈局2個SearchViews:兩個SearchViews在一個活動和屏幕旋轉
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SearchView
android:id="@+id/my_first_custom_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</SearchView>
<SearchView
android:id="@+id/my_second_custom_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/my_first_custom_view" >
</SearchView>
</RelativeLayout>
而且我通過膨脹的setContentView這個佈局我的MainActivity()。然後,我爲對方調用方法 setQuery()。
一切都很好,直到屏幕旋轉。 當我旋轉屏幕時,每個searchView都有文本「World」,而不是「Hello」和「World」。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SearchView firstSearchView = (SearchView) findViewById(R.id.my_first_custom_view);
SearchView secondSearchView = (SearchView) findViewById(R.id.my_second_custom_view);
firstSearchView.setQuery("Hello!", false);
secondSearchView.setQuery("World", false);
}
}
有人可以解釋發生了什麼問題嗎?
這是您的searchviews得到的唯一參考是在onCreate?我假設沒有..如果不是,那麼你可能想發佈相關的代碼 – JoxTraex 2013-02-22 13:14:22
我試過你的代碼,並有與你一樣的行爲...所以一切重現該問題是在 – ben75 2013-02-22 13:16:06
是的,這是唯一的一個參考。我不再使用它了。 – lukjar 2013-02-22 13:18:34