ViewPager
에는 5 개의 슬라이딩 탭이 있습니다. 각각 다른 조각을 가지고 있습니다. 데이터가로드되지 않으면 Snackbar를 통해 사용자에게 알리고 싶습니다. 괜찮 았어.특정 조각의 스낵바
내가 얻으려고하는 것은 데이터가 특정 조각에서로드되지 않으면 그 특정 조각에만 Snackbar
을 표시하고 싶다는 것입니다. 가능한가?
나는 정교한 것이다 :
는 모든 3 개 조각이 데이터를 일부 네트워크 쿼리를 수행하고로드 A, B, & C. 등 3 개 조각으로 슬라이딩 탭 레이아웃을 고려하십시오. 어떤 이유로 인해 데이터가 조각 A에로드되지 않으면 스낵바가 무기한 표시되어야합니다. 그리고 사용자가 조각 B (데이터가 성공적으로로드 된)로 슬라이드하면 스낵바가 보이지 않아야합니다.
따라서 스낵바는 데이터를로드하지 못한 부분에서만 볼 수 있어야합니다.
조각 코드 :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_latest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/windowBackground"
tools:context=".MainFragment">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/date_layout"
android:visibility="gone"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/country_select"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/country"
/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/month_select"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/month"
/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/year_select"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/year"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/latest_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/not_available"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:textSize="16sp" />
</LinearLayout>
플로팅 작업 코드 :
if (Utils.isNetworkAvailable(getActivity())) {
adapter.notifyDataSetChanged();
loadData();
} else {
swipeRefreshLayout.setRefreshing(false);
textView.setText(getString(R.string.check_internet));
Snackbar.make(frameLayout, "Loading failed.", Snackbar.LENGTH_INDEFINITE).setAction("Retry", new View.OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity) getActivity()).loadAds();
refreshData();
}
}).show();
}
어디
FrameLayout frameLayout = (FrameLayout) v.findViewById(R.id.fragment_latest);
이 ** 내가 플로팅 작업을 보여주고 싶은
setUserVisibleHint
와 조각 글로벌 변수에 저장 snakbar를 오버라이드 (override)입니다 그 특별한 조각에서만. 가능합니까? ** 이것으로 무엇을 의미합니까? 조각이 보이면 snakcbar 만 보여줄 것입니다. –@NJ 게시물을 더 자세히 업데이트했습니다. 저것 좀 봐. – hemantv
조각에서 스낵바 패스보기를 보면서보기가 보이지 않을 때 sanckbar가 자동으로 보이지 않게 됨 –