我想查看点击 - >数据更改 - >查看完成 - >片段重置
它正在做:
public class CustomView extends View{
@Override
protected void onDraw(Canvas canvas) {
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
switch (which) {
case 1: {
@Override
public void onClick(DialogInterface dialog, int which) {
Fragment fragment = new Z_Hello();
FragmentManager manager = fragment.getFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.replace(R.id.pager, new Z_Hello());
ft.commit();
}
}
}
也做,但都是错误
Fragment frg = new Z_Hello();
frg = frg.getFragmentManager().findFragmentById(R.id.pager);
final FragmentTransaction ft = frg.getFragmentManager().beginTransaction();
ft.detach(frg); ft.attach(frg); ft.commit();
请帮帮我!
答案 0 :(得分:0)
首先,在onDraw中执行这样的代码 - 第一种踩刹车的方法。 最简单的方法是断开并重新连接片段:
Fragment frg = null;
frg = getFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();