2014-12-19 3 views
0

목록보기 하단에 진행률 표시 줄을 표시하려고합니다.addFooterView를 사용할 때 진행 표시 줄이 표시되지 않습니다.

목록 맨 아래로 스크롤하면 더 많은 항목이로드되고 진행률 표시 줄이 표시되고로드가 완료되면 진행률 표시 줄이 숨겨집니다.

그러나 현재 나는 진행률 막대를 표시하는 데 집착하고 있습니다 (처리하기 쉽기 때문에 아직 표시하거나 숨기는 것에 신경을 쓰지 않습니다). StackOverflow에 많은 솔루션을 적용했지만 작동하지 않았습니다.

이것은 내 목록 조각에 바닥 글보기를 추가하는 방법입니다 :

public class ItemListFragment extends ListFragment { 
    protected View footerView; 

    public ItemListFragment() { 

    } 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
     final LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     this.footerView = li.inflate(R.layout.progress_bar, null); 
     getListView().addFooterView(this.footerView); 
    } 
} 

내 progress_bar.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ProgressBar 
     android:id="@+id/progress_bar" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

내 fragment_item_list.xml 안드로이드 스튜디오에 의해 생성 된 기본 파일 (I 게시입니다 당신이 그것을 필요로하는 경우에 대비하여)

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 

당신은 해결책이있는 경우에 당신의 대답을 게시하십시오. 감사!

답변

0

음, ListFragment 대신 Fragment를 사용하도록 전환하여 문제를 해결했습니다.

내 조각 :

public class TestFragment extends Fragment { 
    static final String[] numbers = new String[] { "one", "two", "three", 
      "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", 
      "twelve", "thirteen", "fourteen", "fifteen", "sixteen", 
      "seventeen", "eighteen", "nineteen", "twenty", "twenty one", 
      "twenty two" }; 

    public TestFragment() { 

    } 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.test_list_view, container, false); 

     ListView listView = (ListView) rootView.findViewById(R.id.test_list_view); 

     View footer = View.inflate(getActivity().getApplicationContext(), R.layout.test_footer, null); 
     listView.addFooterView(footer); 

     ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, numbers); 

     listView.setAdapter(adapter); 

     return rootView; 
    } 
} 

test_list_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ListView 
     android:id="@+id/test_list_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

</LinearLayout> 

test_footer.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="match_parent" 
    android:orientation="vertical" > 

    <ProgressBar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 
관련 문제