0
我在PageViewer中有一些片段。 在主要片段中,如果没有连接,我想显示一个组件(TextView或imageView)。 在下面的代码中,我可以达到我的textview,但我无法让它们消失。更改片段中的TextView可见性
public class MainFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.main, container, false);
// RelativeLayout mainLayout = (RelativeLayout)findViewById(R.layout.main);
TextView TxtIsNotConnected = (TextView) layout.findViewById(R.id.isNotConnected);
TextView TxtIsConnected = (TextView) layout.findViewById(R.id.isConnected);
// String text = TxtIsNotConnected.getText().toString(); // This is a test which works, return the text o my textview.
boolean isConnected = ConnectivityUtils.isConnected(getActivity()); // This Works fine
if (!isConnected) TxtIsNotConnected.setVisibility(View.VISIBLE); // NOT WORKING
else TxtIsConnected.setVisibility(View.VISIBLE); // NOT WORKING
return inflater.inflate(R.layout.main, container, false);
}
我该怎么办?
问题不是逻辑,问题是我无法更新可视性!我更新了代码,但它仍然没有设置可见性:( –
查看我的更新回答。 – ayon
问题解决!Tx! –