我正在使用listview和其他视图(tablayout和viewpager)创建一个布局。
我将列表视图设置为“消失”,其他视图可见。
当我将listview更改为VISIBLE并将其他更改为GONE时,Listview不显示任何内容。
可能是什么原因造成的?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tab_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill"
app:tabMode="scrollable"
app:tabTextColor="@color/colorPrimary"
app:tabIndicatorColor="@color/colorPrimaryDark"
app:tabSelectedTextColor="@color/colorPrimaryDark" />
<android.support.v4.view.ViewPager
android:id="@+id/tab_view_page"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include layout="@layout/search_listview_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"/>
</LinearLayout>
这是我的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.app_bar_menu_mrecords, menu);
searchView_mrecords = (SearchView) menu.findItem(R.id.bt_search_mrecords).getActionView();
searchView_mrecords.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter_search_patient_info.getFilter().filter(newText);
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//when click button search , show listview and visible other view
case R.id.bt_search_mrecords:
tabLayout_patient_info.setVisibility(View.GONE);
viewPager_patient_info.setVisibility(View.GONE);
listView_search_patients.setVisibility(View.VISIBLE);
return true;
}
return super.onOptionsItemSelected(item);
}