나는이 problem을 포함하는 더 긴 질문을 이미 요청했습니다. 큰 문제를 작은 문제로 세분화하려고합니다. 뷰의 가시성 특성을 프로그래밍 방식으로 변경
나는 안드로이드를 변경하려고 해요 : 가시성 = 프로그램과 같이 "사라"XML을 : 이것은 MainAction.java의 레이아웃과 조각 3 개 컨테이너가. fragment_C는 표시되지 않아야하며 사용자가 .replace (R.id.fragment_C, new FragmentC())를 사용하여 버튼을 탭하면 채워집니다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:paddingLeft="0dp"
android:paddingRight="0dp" >
<LinearLayout
android:id="@+id/fragments_container"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:baselineAligned="false" >
<FrameLayout
android:id="@+id/fragment_A"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:background="#CCCCCC" >
</FrameLayout>
<FrameLayout
android:id="@id/fragment_B"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:background="#B4B4B4"
>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/fragment_C"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/fragment_container"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:background="#A3A3A3"
android:visibility="gone" >
</FrameLayout>
</RelativeLayout>
FragmentC을 추가하고 가시성 속성을 변경 해야하는 버튼의 코드 :이 세계에서 NullPointerException이 무엇을 얻을 않는 이유이
public class FragmentB extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragmentB, container, false);
ListView listView = (ListView) view.findViewById(R.id.listView1);
Button button = (Button) view.findViewById(R.id.button);
String[] machines = new String[] { "MachineId-001", "MachineId-002", "MachineId-003", "MachineId-004", "MachineId-005", "MachineId-006", "MachineId-007", "MachineId-008"};
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_multichoice, machines));
final FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.fragment_C);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null) {
getFragmentManager().beginTransaction().replace(R.id.fragment_C, new FragmentC()).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).addToBackStack(null).commit();
// When using setVisibility the app crashes with a
// java.lang.NullPointerException
frameLayout.setVisibility(View.VISIBLE);
}
}
});
return view;
}
}
사람이 말해 줄 수 오전 나는 일을 코드가 잘못 되었나요?
추가 데이터 :
내 FrameLayout이 변수가 널 것을 발견 응용 프로그램을 디버깅 후. 이게 왜 널 모르는지 모르겠어.
이 포럼의 사용자는 추가 플래그를 추가 할 것을 제안했습니다. 하지만 그건 효과가 없었습니다. – sebster