아래의 형태로
Main에서 Fragment가 BluetoothFragment일때
BluetoothFragment의 textview를 변경할려고하는데
아래와 같이 실행을하면 Nullpointexception이 발생합니다.
Fragment에서 textview가 생성되기전에 실행이 되어서 그런건가요?
수정할수 있는 방안이 없는가요??
fragment가 여러개가 있어서 해당 fragment일경우에만 실행을 하고 싶어서
아래와 같이 구현을 하였습니다.
Mainactivity
BluetoothFragment checkbluetooth = (BluetoothFragment) getSupportFragmentManager().findFragmentById(R.id.bluetooth_fragment);
if(String.valueOf(fragment).contains("BluetoothFragment")) {
checkbluetooth.BT_Connect();
}
Fragment
ublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
text_bt = (TextView) view.findViewById(R.id.bluetooth_state);
}
public void BT_Connect() {
~~~~~~~~~~
}
public void BT_Disconnect() {
~~~~~~~~~
}