ListView에서 바닥 글보기를 숨기시겠습니까?
나는 ListView
. 그 뒤에있는 데이터는 사용자가 맨 아래까지 스크롤 할 때마다 10-30 개의 항목 집합으로 인터넷에서 가져옵니다. 더 많은 항목을로드하고 있음을 나타 내기 위해 addFooterView()
"Loading ..."메시지와 스피너를 표시하는 간단한보기를 추가했습니다. 이제 데이터가 부족할 때 (더 이상 가져올 데이터가 없음) 해당 메시지를 숨기고 싶습니다. 나는 시도했다 :
loadingView.setVisibility(View.GONE);
안타깝게도 뷰가 숨겨 지지만 공간이 남습니다. 즉, "Loading"메시지가 있던 곳에 큰 공백이 생깁니다. 이 뷰를 제대로 숨기려면 어떻게해야합니까?
removeFooterView()
다시 표시해야 할 수 있으므로 사용할 수 없습니다 .이 경우 addFooterView()
어댑터가에 이미 설정되어있어 다시 전화를 ListView
걸 수 없으며 어댑터를 설정 한 후 addHeaderView()
/ addFooterView()
를 호출 할 수 없습니다 .
적어도 한 번 전에 해당 메서드 중 하나를 호출하는 한 addHeaderView()
/ addFooterView()
후에 호출 할 수있는 것 같습니다 . 그것은 구글의 디자인 결정이 다소 좋지 않아서 문제를 제기했습니다 . 이것을 결합하면 내 솔루션이 있습니다.setAdapter()
removeFooterView()
내가 얻은 다른 두 답변에 +1은 유효한 (그리고 틀림없이 더 정확한) 솔루션입니다. 그러나 내 것이 가장 간단하고 단순함을 좋아하므로 내 답변을 수락 된 것으로 표시하겠습니다.
바닥 글을 숨기기 전에 바닥 글 높이를 0px 또는 1px로 설정해보세요. 또는 바닥 글보기를 wrap_content
높이로 감싸고 FrameLayout
내부보기를 숨기거나 표시하여 FrameLayout
표시합니다. 높이가 적절하게 감싸 야합니다.
제 경우에는 addFooterView / removeFooterView ()로 인해 일부 인공물이 발생합니다. 그리고 다른 해결책을 찾았습니다. FrameLayout을 FooterView로 사용했습니다. 그리고 Footer를 추가하고 싶을 때 mFrameFooter.addView (myFooter); 및 mFrameFooter.removeAllViews (); 제거를 위해.
FrameLayout frameLayout = new FrameLayout(this);
listView.addFooterView(frameLayout);
......
......
//For adding footerView
frameLayout.removeAllViews();
frameLayout.addView(mFooterView);
//For hide FooterView
frameLayout.removeAllViews();
Droid-Fu 라이브러리에는로드 바닥 글을 표시하고 숨기도록 설계된 클래스가 있습니다. ListAdapterWithProgress .
내 프로젝트에서 잘 작동합니다.
1. 먼저 바닥 글보기 추가
mListView.addFooterView(mFooterView); mListView.setAdapter(mAdapter);
2. 가시성 설정
mFooterView.setVisibility(View.GONE); mFooterView.setPadding(0, 0, 0, 0);
3. 비공개 설정
mFooterView.setVisibility(View.GONE); mFooterView.setPadding(0, -1*mFooterView.getHeight(), 0, 0);
@YoniSamlan이 지적했듯이 간단한 방법으로 달성 할 수 있습니다. 지정해야합니다
android:layout_height="wrap_content"
"추가로드"단추를 포함하는 ViewGroup에서. FrameLayout 일 필요는 없습니다. LinearLayout을 사용하는 간단한 작업 예제는 아래를 참조하십시오.
두 이미지 모두 맨 아래로 스크롤되는 화면을 보여줍니다. 첫 번째 항목에는 "추가로드"버튼을 둘러싼 보이는 바닥 글이 있습니다. 두 번째 이미지는 버튼의 가시성을 GONE으로 설정하면 바닥 글이 축소되는 것을 보여줍니다.
가시성을 변경하여 바닥 글 (일부 콜백 내부)을 다시 표시 할 수 있습니다.
loadMore.setVisibility(View.VISIBLE); // set to View.GONE to hide it again
평소대로 listView 초기화를 수행하십시오.
// Find View, set empty View if needed
mListView = (ListView) root.findViewById(R.id.reservations_search_results);
mListView.setEmptyView(root.findViewById(R.id.search_reservations_list_empty));
// Instantiate footerView using a LayoutInflater and add to listView
footerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.load_more_footer_view, null, false);
// additionally, find the "load more button" inside the footer view
loadMore = footerView.findViewById(R.id.load_more);
loadMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
fetchData();
}
});
// add footer view to the list
mListView.addFooterView(footerView);
// after we're done setting the footerView, we can setAdapter
adapter = new ReservationsArrayAdapter(getActivity(), R.layout.list_item_reservations_search, reservationsList);
mListView.setAdapter(adapter);
load_more_footer_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/load_more"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="9dp"
android:gravity="center"
android:layout_gravity="center"
android:background="@drawable/transparent_white_border"
android:textColor="@android:color/white"
android:text="@string/LOAD_MORE"/>
Android의 버그 일 것입니다.
바닥 글보기를 동적으로 제거하거나 추가 할 필요가 없습니다. 지정되지 않은 높이 부모 레이아웃 (xml 파일에서 확장하거나 프로그래밍 방식으로 생성)을 만든 다음 숨기거나 표시 할 뷰를 추가하기 만하면됩니다.
And you can set the view, but NOT the parent Layout, to VISIBLE or GONE or something else now. It works for me.
Used
footer.removeAllViews();
This does not remove footer but flushes children. You again have to repopulate children. Can check by
footer.getChildCount()<2
I also found that is possible call onContentChanged()
(if you use ListActivity
) to force recreate ListView
if I need add HeaderView
to them after setAdapter()
call, but it is very ugly hack.
I have created a ListView that handles this. It also has an option to use the EndlessScrollListener I've created to handle endless listviews, that loads data until there's no more data to load.
You can see these classes here:
https://github.com/CyberEagle/OpenProjects/blob/master/android-projects/widgets/src/main/java/br/com/cybereagle/androidwidgets/helper/ListViewWithLoadingIndicatorHelper.java - Helper to make it possible to use the features without extending from SimpleListViewWithLoadingIndicator.
https://github.com/CyberEagle/OpenProjects/blob/master/android-projects/widgets/src/main/java/br/com/cybereagle/androidwidgets/listener/EndlessScrollListener.java - Listener that starts loading data when the user is about to reach the bottom of the ListView.
https://github.com/CyberEagle/OpenProjects/blob/master/android-projects/widgets/src/main/java/br/com/cybereagle/androidwidgets/view/SimpleListViewWithLoadingIndicator.java - The EndlessListView. You can use this class directly or extend from it.
이 문제를 모든 곳에서 해결할 수있는 작은 해킹 방법이 있습니다. LinnearLayout과 같은 부모 레이아웃에 목록보기 및 바닥 글보기 (하위 레이아웃 만)를 넣고 목록보기 아래의 바닥 글보기를 기억하십시오.
이 바닥 글보기가 사라지고 일반보기처럼 가시성을 제어합니다. 그리고 끝났습니다!
먼저 다음과 같이 내 바닥 글을 목록보기에 추가합니다.
listView.addFooterView(Utils.b);
그런 다음 버튼을 클릭하면보기를 제거하고
listView.removeFooterView(Utils.b);
비동기를 눌렀을 때마다 바닥 글을 추가하고 있으며 중복 항목이 없습니다. 또한 카운트를 확인할 수 있습니다.
if(listView.getFooterViewsCount() > 0){//if footer is added already do something}
ListView
그냥 통화 에서 바닥 글을 제거하고 싶을 때
listView.addFooterView(new View(yourContext));
공간을 예약하지 않는 더미 빈 뷰를 추가합니다.
참고 URL : https://stackoverflow.com/questions/4317778/hide-footer-view-in-listview
'development' 카테고리의 다른 글
.NET에 직렬화 가능한 일반 키 / 값 쌍 클래스가 있습니까? (0) | 2020.10.12 |
---|---|
emacs에서 줄 / 영역을 위아래로 이동 (0) | 2020.10.12 |
부하 대 스트레스 테스트 (0) | 2020.10.12 |
Git : 병합 된 브랜치가 아닌이 브랜치에 커밋을 나열하는 방법 (0) | 2020.10.12 |
Rails에서 force_ssl은 무엇을합니까? (0) | 2020.10.12 |