Maison > Questions et réponses > le corps du texte
界面是这样的:
我用tab+viewpager实现了一个这种选项卡加滑动的效果,然后实际上是每次都是按下上面那个consume或者income才inflate一个跟其对应的layout,所以我每次inflate的layout里面所有的button都是unchecked状态。(consume选项会inflate consume.layout;income选项会inflate income.layout)
但是我想要实现:这个页面可以接收一个参数(这个参数指定哪个button需要变成checked状态),当进入这个页面时某个button直接就处于checked状态了,就像下面这样:
然后我思路的问题是 我不知道该怎样得到inflate consume.layout或inflate income.layout后返回的view,所以就无法(Button)view.findViewById(R.id.button).setChecked(true)。
问题:
1.跪求大佬给个解决办法,或者其他能实现这种效果的思路。
2.另:这里的Button其实我是想弄一个radiobutton的,但是我又不想用radiogroup默认的linearlayout,然后就自己弄的一个relativelayout,但这样单选就失效了,我看stackoverflow上说只能手动给每个button添加一个onclicklistener事件实现单选。请问还有其他解决方法可以让它恢复单选吗?
高洛峰2017-04-18 10:32:56
Deux solutions :
1
pageAdapter.instantiateItem(viewpager, position)
2 Utiliser EventBus
PHPz2017-04-18 10:32:56
Si vous utilisez FragmentPagerAdapter
, vous n'avez pas besoin d'obtenir la vue spécifique, récupérez simplement le fragment correspondant, puis fournissez des méthodes dans le fragment pour mettre à jour la vue à l'intérieur.
ViewPager peut faire référence à ViewPager+Fragment pour obtenir une instance de Fragment. Lorsqu'une donnée dans un certain Fragment change, ma réponse est dans cette question : Comment actualiser partiellement ces données.
PHP中文网2017-04-18 10:32:56
Retrouvez dans votre adaptateur :
@Override
public Object instantiateItem(ViewGroup container, int position) {
return super.instantiateItem(container, position);
}
L'objet renvoyé ici est votre nouvelle page, et vous pouvez récupérer votre bouton sous fvb