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! –