저는 안드로이드 개발에 초보자입니다. 이제 프래그먼트간에 메소드를 호출 할 때 문제가 발생합니다. 설명해 드리겠습니다. 모두가 해결할 수 있도록 노력하겠습니다.프래그먼트 A에서 프래그먼트 B의 메소드를 실행하는 방법
조각
public class A extends Fragment implements OnItemClickListener {
.........
.........
.........
public void showContent(int pSelectedIndex, int pSelectedSubIndex) {
// Create fragment and give it an argument specifying the article it
RelativeLayout thisTopLayout = (RelativeLayout)getActivity().findViewById(R.id.directoryTopRelativeLayout);
thisTopLayout.setVisibility(LinearLayout.GONE);
RelativeLayout thisBodyLayout = (RelativeLayout)getActivity().findViewById(R.id.directoryBodyRelativeLayout);
thisBodyLayout.setVisibility(LinearLayout.GONE);
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
if (pSelectedIndex == 1) {
BusinessView thisItem = new BusinessView();
transaction.replace(R.id.directoryLayout, thisItem);
thisItem.DetectContentType(pSelectedSubIndex, this.getActivity());
}
}
}
조각 B
public class B extends Fragment implements OnItemClickListener {
@SuppressWarnings("deprecation")
public void DetectContentType(int selectedType, Activity pActivity){
if (selectedType != 1) {
AlertDialog alertDialog = new AlertDialog.Builder(pActivity)
.create();
alertDialog.setTitle("EXAMPLE");
alertDialog
.setMessage("SHOW MESSAGE");
alertDialog.setButton("YES", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,
final int which) {
// here you can add functions
}
});
alertDialog.setButton2("NO", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog,
final int which) {
// here you can add functions
}
});
alertDialog.show();
} else {
showContent(selectedType);
}
}
public void showContent(int pSelectedIndex) {
// Create fragment and give it an argument specifying the article it
RelativeLayout thisTopLayout = (RelativeLayout) this.getActivity().findViewById(R.id.businessTopRelativeLayout);
thisTopLayout.setVisibility(LinearLayout.GONE);
RelativeLayout thisBodyLayout = (RelativeLayout) this.getActivity()
.findViewById(R.id.businessBodyRelativeLayout);
thisBodyLayout.setVisibility(LinearLayout.GONE);
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
BusinessItemView thisItem = new BusinessItemView(pSelectedIndex);
transaction.replace(R.id.businessLayout, thisItem);
// Commit the transaction
transaction.commit();
}
}
내 수업은 내가 조각 (A)에 오전 때 조각 B의 방법 "showContent"를 실행하고자한다
,하지만 난 그냥 표시 할 수 있습니다 경고하지만 "showContent"메서드는 항상 오류가 발생합니다.
이 사례에 대해 알려주십시오. 정말 고마워요.
logcat 출력을 추가하십시오. – Booger