0
나는 this을 사용하고 카드보기가있는 리사이클 러보기를 탭 아래에 두었습니다. 첫 번째 탭만 재활용보기를 표시하고 다른 탭은 표시하지 않습니다. 탭이 잘 보이고 첫 번째 조각이 잘 보이지만 다른 탭으로 스 와이프하려고하면 조각이 표시되지 않습니다.첫 번째 조각 만 tablayout 아래에 표시됩니다.
내 코드 : 홈페이지 activty 레이아웃 :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
tools:context="codycoogan.equations.about_activity"
android:orientation="vertical"
>
<include layout="@layout/tool_bar"
android:id="@+id/toolBar"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/viewPagerContainer"
/>
</LinearLayout>
tablayout 및 viewpager를 가지고 위의 FrameLayout이에 대한 레이아웃 :
public class mainViewPagerFragment extends Fragment {
private TabLayout tabLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_main_view_pager, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.favoritesRecycler);
ViewPager viewPager = (ViewPager)view.findViewById(R.id.pager);
setupViewPager(viewPager);
tabLayout = (TabLayout)view.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
return recyclerView;
}
private void setupViewPager(ViewPager viewPager) {
ViewPageAdapter adapter = new ViewPageAdapter(getChildFragmentManager());
adapter.addFragment(new RecyclerFragment(), "ONE");
adapter.addFragment(new favoritesFragment(), "TWO");
viewPager.setAdapter(adapter);
}
class ViewPageAdapter extends FragmentStatePagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPageAdapter(FragmentManager fragmentManager){
super(fragmentManager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
: tablayout 및 viewpager에 대한 설정
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
android:background="@color/colorPrimary"
app:tabGravity="fill"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:id="@+id/pager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:clickable="true"
/>
</android.support.design.widget.CoordinatorLayout>
}
내 조각 : 내 문제를 파악
public class RecyclerFragment extends Fragment { //FOR GEOMETRY
private Cursor cursor;
private SQLiteDatabase db;
private Vibrator vibrator;
private int[] imageArray = {
R.mipmap.circle55,
R.mipmap.circle55,
R.mipmap.circle55,
R.mipmap.circle55,
R.mipmap.octagon55,
};
private ArrayList<Integer> image = new ArrayList<>();
private ArrayList<String> names = new ArrayList<>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
new listPop().execute();
populateImageArray();
vibrator = (Vibrator)getActivity().getSystemService(Context.VIBRATOR_SERVICE);
RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.recylcler_layout, container, false);
recylcerAdapter RecylcerAdapter =
new recylcerAdapter(image.toArray(new Integer[image.size()]), names.toArray(new String[names.size()]));
LinearLayoutManager manager = new LinearLayoutManager(getActivity());
manager.canScrollVertically();
recyclerView.setLayoutManager(manager);
recyclerView.setAdapter(RecylcerAdapter);
RecylcerAdapter.setListener(new recylcerAdapter.Listener() {
public void onClick(int position) {
vibrator.vibrate(50);
Intent intent = new Intent(getActivity(), EquationsActivity.class);
intent.putExtra(EquationsActivity.POSITION, position);
getActivity().startActivity(intent);
}
});
return recyclerView;
}
private class listPop extends AsyncTask<Integer, Void, Boolean> {
@Override
protected Boolean doInBackground(Integer... equate) {
SQLiteOpenHelper databaseHelper = new DatabaseHelper(getActivity());
try {
db = databaseHelper.getReadableDatabase();
cursor = db.query("EQUATIONTABLE", new String[]{"_id", "NAME"}, null, null,
null, null, "SORTORDER ASC");
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
names.add(cursor.getString(cursor.getColumnIndex("NAME")));
cursor.moveToNext();
}
return true;
} catch (SQLiteException e) {
e.printStackTrace();
return false;
} finally {
cursor.close();
db.close();
}
}
@Override
protected void onPostExecute(Boolean success) {
checkFirstRun();
if (!success) {
Toast toast = Toast.makeText(getActivity(), "Database Error", Toast.LENGTH_LONG);
toast.show();
}
}
}
을 실행 한 비동기 작업의 onPostExecute에서 아래에 아래 코드를 삽입해야한다는 것입니다 그것은을 위해 잘 작동 저, 제발 우리가 볼 수 있도록 코드를 게시하시기 바랍니다. – amitairos
을 게시하시기 바랍니다
– AmanSinghal@amitairos 내가 게시했습니다 –