Skip to content

Commit

Permalink
Finished setting up second tablayout inside SubletterFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
vavali08 committed Dec 4, 2023
1 parent d134fd6 commit b41a668
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.pennapps.labs.pennmobile.adapters.SubletterPagerAdapter

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"


/**
* A simple [Fragment] subclass.
Expand All @@ -32,7 +32,23 @@ class SubletterFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_subletter_view, container, false)
val rootView = inflater.inflate(R.layout.fragment_subletter_view, container, false)
viewPager = rootView.findViewById(R.id.subletter_view_pager)
subletterPagerAdapter = SubletterPagerAdapter(this)
viewPager.adapter = subletterPagerAdapter

val tabLayout: TabLayout = rootView.findViewById(R.id.subletter_tab_layout)
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
if(position == 0) {
tab.text = "Posted"
} else {
tab.text = "Drafts"
}

}.attach()

return rootView

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ class SubletterHolderFragment : Fragment() {
subletterPagerAdapter = SubletterPagerAdapter(this)
viewPager = view.findViewById(R.id.viewPager2)
viewPager.adapter = subletterPagerAdapter
val tabLayout : TabLayout = view.findViewById(R.id.subletting_tab_layout)
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
tab.text = "OBJECT ${(position + 1)}"
}.attach()


}

Expand Down
4 changes: 3 additions & 1 deletion PennMobile/src/main/res/layout/fragment_subletter_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
android:id="@+id/subletter_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/my_listings_text"
/>
app:tabIndicatorColor="@color/color_bottom_nav_selected"
app:tabTextAppearance="@style/TextAppearance.AppCompat.Small" />

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/subletter_view_pager"
Expand Down

0 comments on commit b41a668

Please sign in to comment.