1
두 개의 클래스가 있습니다.안드로이드의 프래그먼트에서 액티비티를 호출하려면 어떻게해야합니까?
ProfileFragment.class
public class ProfileFragment extends Fragment implements OnClickListener {
Fragment fragment = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_profile, container,false);
return rootView;
}
}
LastCheckins.class 프로그램이 ProfileFragment 클래스를 만들 때이 작업 클래스를 호출 할 수있는 방법
public class LastCheckins extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView sv = (ScrollView) findViewById(R.id.scrollView1);
LinearLayout ll = (LinearLayout) findViewById(R.id.LinearLayout1);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);
for (int i = 0; i < 20; i++) {
CheckBox cb = new CheckBox(this);
cb.setText("I'm dynamic!");
ll.addView(cb);
}
this.setContentView(sv);
}
}
?
고마워요.
이 그냥 잘못 : 당신이 metods를 호출하고 눈에 보이는 필드에 액세스 할 수 있도록
당신은 LastChekins에 캐스팅 할 수 있습니다. 'findViewById'는 찾을 뷰가 없을 때 항상 리턴합니다. 단편은 활동에서 직접 작성할 때까지 작성되지 않습니다. 레이아웃 파일을 사용하고'setContentView'를 사용하여 파일을 팽창시켜야합니다. – Simas