0

I have a Fragment and partial code from my app is:

mFrame3 =  (RelativeLayout) inflater.inflate( R.layout.ptrip, container, false ); //display if file exist
noFilesDisplayed = (RelativeLayout) inflater.inflate(R.layout.nofile, container, false); //display if file doesn't exist

if (FilesInFolder != null) { //function to check if any file exist
    mFrame3.findViewById(R.layout.ptrip).setVisibility(View.VISIBLE); //display this layout
    noFilesDisplayed.findViewById(R.layout.nofile).setVisibility(View.GONE); //hide this layout
}
else {
    mFrame3.findViewById(R.layout.ptrip).setVisibility(View.GONE);
    noFilesDisplayed.findViewById(R.layout.nofile).setVisibility(View.VISIBLE);
}

I am not sure if it's the best way but what I am looking to do is if there are any files in the directory to show the mFrame3 RelativeLayout XML file and hide noFilesDisplayed otherwise show the noFilesDisplayed RelativeLayout XML file and hide mFrame3.

4

2 回答 2

0

如果每个片段生命周期发生一次,只需在onCreateView函数中执行此操作,并且不要同时膨胀可见和不可见布局。

于 2013-08-06T13:14:01.680 回答
0

如果要显示/隐藏整个“mFrame3”或“noFilesDisplayed”视图,只需调用 mFrame3.setVisibility() 和 noFilesDisplayed.setVisibility()...

于 2013-08-06T13:28:22.737 回答