在我的活动中,我有3个标签。 TabFrag A,TabFrag B和TabFrag C。
TabFragB是一个列表视图。每个视图里面都有一个按钮。
当我按下该按钮时,新片段应该替换当前视图。
但是,我收到了一个java null point错误。
代码:TabFrag B。
public class TabDelta extends Fragment implements ActionBar.TabListener
{
private Fragment mFragment;
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.listview, container, false);
ListView tabbList = (ListView) view.findViewById(R.id.ListConsole);
Adapter_TabBList a_tabbList = new Adapter_TabBList(getActivity(),gs.Members,mFragment);
deltaList.setAdapter(a_tabbList);
return view;
}
public void onTabSelected(Tab tab, FragmentTransaction ft)
{
mFragment = new TabDelta();
ft.add(R.id.LLfragmentconsole, mFragment);
ft.attach(mFragment);
}
}
CODE ADAPTER(Adapter_TabBList):
public class Adapter_TabBList extends ArrayAdapter<Member>
{
private final FragmentActivity context;
private final ArrayList<Member> values;
//private final String tag;
Fragment f;
GlobalState gs;
public Adapter_TabBList(FragmentActivity context, ArrayList<Member> values,Fragment f)
{
super(context, R.layout.lr_tabb, values);
this.context = context;
this.values = values;
this.gs = (GlobalState) context.getApplication();
//this.tag = tag;
this.f = f;
}
OnCLICK LISTNER INSIDE ADAPTER:
holder.add.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
FragmentManager fm = context.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack(f.getTag()); //LINE 116
ft.hide(f);
//ft.addToBackStack(tag);
//ft.hide(fm.findFragmentById(tag));
ft.add(R.id.LLfragmentconsole,new addEvent(), "NEW_EVENT");
ft.commit();
}
});
logcat的:
01-10 10:09:40.662: E/AndroidRuntime(1387): FATAL EXCEPTION: main
01-10 10:09:40.662: E/AndroidRuntime(1387): Process: com.ani.tf, PID: 1387
01-10 10:09:40.662: E/AndroidRuntime(1387): java.lang.NullPointerException
01-10 10:09:40.662: E/AndroidRuntime(1387): at com.ani.tf.Adapter_TabBList$1.onClick(Adapter_TabBList.java:116)
ERROR位于ft.addToBackStack(f.getTag())
我不想按照我想要的替换片段命令返回TabFragB。
非常感谢您的帮助。