단편 B의 단편 A에서 Textview에 액세스하려고 시도하면 텍스트가 바뀌고 메신저에는 Null 포인터가 생깁니다. 필자는 다음을 시도했다.단편 B의 단편 A에서보기 액세스
public void setText(String text) { TextView t = (TextView) getView().findViewById(R.id.message_menu); t.setText(text); }
은 또한 너무
View myFragmentView = inflater.inflate(R.layout.fragment_login, container, false);
test = (TextView) test..findViewById(R.id.message_menu);
가
test = (TextView) FragmentLogin.newInstance().getView().findViewById(R.id.TEXT_STATUS_ID);
test.setText("hello testing ");
조각 B에서 다음 코드를 newInstance와 사용하여 시도 다른보기 팽창 시도
test = (TextView) getView().findViewById(R.id.message_menu);
test.setText("bla bla");
시도했다
그리고 조각 A :
public static FragmentBottomMenu newInstance() {
FragmentBottomMenu fragment = new FragmentBottomMenu();
return fragment;
}
여전히 널 포인터 예외를 받고.
어떤 제안이 좋을 것입니다. 감사합니다
이렇게하지 마십시오. 단지 나쁜 습관 일뿐입니다. 텍스트 변경의 원인이되는 이벤트를 액티비티에 알리고, 액티비티가 두 번째 조각에서 public 메서드를 호출하게합니다. – kcoppock