Skip to content

Commit

Permalink
add togglebutton relate with viewpager
Browse files Browse the repository at this point in the history
  • Loading branch information
root14 committed Mar 26, 2024
1 parent 0bc4d5d commit 50de352
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/com/root14/hoopoe/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewpager2.widget.ViewPager2
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.root14.hoopoe.databinding.ActivityMainBinding
import com.root14.hoopoe.view.adapter.CoinRecycleAdapter
import com.root14.hoopoe.view.adapter.MainPagerAdapter
Expand Down Expand Up @@ -59,6 +61,21 @@ class MainActivity : AppCompatActivity() {
binding.btnCoins.setOnClickListener {
binding.viewpager.currentItem = 0
}

binding.viewpager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
when (position) {
0 -> {
binding.toggleButton.check(R.id.btn_coins)
}

1 -> {
binding.toggleButton.check(R.id.btn_watchList)
}
}
}
})
}

private fun setupViewPagerAdapter() {
Expand Down

0 comments on commit 50de352

Please sign in to comment.