我在android中实现片段,我遇到了问题:
public Fragment getItem(int num) {
switch (num)
{
case 0:
NewFragment newFragment = new NewFragment();
//newFragment.refresh();
return newFragment;
case 1:
HotFragment hotFragment = new HotFragment();
//hotFragment.refresh();
return hotFragment;
default: return new ContentFragment();
}
}
当我点击标签主机中的按钮时,它会调用" onCreateView"和" onViewCreated"只有一次。但是我的目的可以在每次调用new NewFragment()时回调函数来处理吗?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_new, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//some config
}
我确实尝试过onDetach(),onAttach(),onResume(),但它不能用于我的目的
答案 0 :(得分:0)
我真的不了解你,但是如果你想刷新你的片段,你可以这样做:
sheet["B1"] = "firstName"
sheet["C1"] = "middleName"
sheet["D1"] = "lastName"
for row in sheet.iter_rows(min_row=2, max_col=2):
id_cell, name = row
fullname = name.value.strip()
namelist = fullname.split()
firstname = namelist[0]
lastname = namelist[-1]
middlename = ""
if len(namelist) >= 3:
middlename = namelist[1]
if len(namelist) == 4:
lastname = " ".join(namelist[-2:])
if middlename in ('Del', 'El', 'Van', 'Da'):
lastname = " ".join([middlename, lastname])
middlename = None
name.value = firstname
name.offset(column=1).value = middlename
name.offset(column=2).value = lastname
wb.save("output.xlsx")