私は1つの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ごとに "Hello"と "World"の代わりに "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
私はあなたのコードを試してみて、あなたと同じ振る舞いをしています...問題を再現するためのすべてが投稿にあります – ben75
はい、 1つの参照。私はもうそれを使用しません。 – lukjar