我从自定义对话框调用片段。但我不能称之为片段。 我的onClick调用函数
public void text_noteClick(View v){
Fragment fragments = new Text_Note_Fragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.layout.note_text, fragments);
transaction.addToBackStack(null);
Toast.makeText(getApplicationContext(),"text",Toast.LENGTH_SHORT).show();
}
Toast成功运作。 Text_Note_Fragment类是
public class Text_Note_Fragment extends Fragment {
public Text_Note_Fragment() {
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view;
view = inflater.inflate(R.layout.note_text,container,false);
return view;
}
} 我认为问题是片段替换功能。 对不起我的英文:) TNX
答案 0 :(得分:0)
我想这一行是根本原因。
@Override
protected void onResume() {
super.onResume();
boolean installed = false;
while (!installed) {
installed = appInstalledOrNot (APPPACKAGE);
if (installed) {
Toast.makeText(this, "App installed", Toast.LENGTH_SHORT).show ();
}
}
}
private boolean appInstalledOrNot (String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
我看到您在transaction.replace(R.layout.note_text, fragments);
函数中使用了R.layout.note_text
,这是您片段的布局xml。但为什么你在替换功能中使用它?你应该使用一个容器(通常是一个FrameLayout),就像这样。
onCreateView