我有一个非常奇怪的问题。我有一个带有片段的寻呼机。片段之一是消息片段。在这个片段中,我有一个带有三个选项卡片段的 FragmentTabHost。在操作栏中,我有一个 SearchView。当我想要搜索某些内容并开始编写查询字符串时,搜索视图的焦点会从中移除并设置到 TabHost 的第一个选项卡。这样我就无法编写查询字符串。仅当我靠近 MessagesFragment 时才会发生这种情况。例如:如果我足够远(1 页),搜索工作正常。
有人可以告诉我可能是什么问题吗?
这是一张图片:
消息片段:
public class MessagesFragment extends Fragment {
private FragmentTabHost tabHost;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
this.tabHost = new FragmentTabHost(this.getActivity());
this.tabHost.setup(this.getActivity(), this.getChildFragmentManager(), container.getId());
TabSpec tabSpecForAllMessages = this.tabHost.newTabSpec("all").setIndicator("ALL");
this.tabHost.addTab(tabSpecForAllMessages, AllMessagesFragment.class, null);
TabSpec tabSpecForSentMessages = this.tabHost.newTabSpec("sent").setIndicator("SENT");
this.tabHost.addTab(tabSpecForSentMessages, SentMessagesFragment.class, null);
TabSpec tabSpecForReceivedMessages = this.tabHost.newTabSpec("received").setIndicator("RECEIVED");
this.tabHost.addTab(tabSpecForReceivedMessages, ReceivedMessagesFragment.class, null);
return this.tabHost;
}
@Override
public void onDestroyView() {
super.onDestroyView();
this.tabHost = null;
}
}
选项卡主机布局:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
操作栏菜单项:
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="@+id/menu_item_search"
android:actionViewClass="android.widget.SearchView"
android:icon="@drawable/ic_action_search"
android:showAsAction="collapseActionView|ifRoom"
android:title="@string/title_search" />
<item
android:id="@+id/menu_item_home"
android:icon="@drawable/ic_action_home"
android:showAsAction="always"
android:title="@string/title_home" />
onCreateOptionsMenu 事件处理程序:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = this.getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.menu_item_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(this
.getComponentName()));
return true;
}