Android 조각을 왜 배우는 지 문제가 있습니다. 내 응용 프로그램에서 3 조각으로 하나의 활동이 있습니다. 각 조각은 일부 사용자 조치 후에 이전을 대체합니다. 내 주요 XML 레이아웃 ID '컨테이너'간단한 FrameLayout입니다. MainActivity onCreate() 메소드에서 컨테이너에 기본 조각을 추가하는 중 :인조 인간 : 액티비티 onCreate() 메소드에서 조각 만들기를 바꿀 수 없습니다.
public class HolderActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
....
FragmentList listFragment = new FragmentList();
// Add the fragment to the 'container'
getSupportFragmentManager().beginTransaction()
.add(R.id.container, listFragment).commit();
초기 화면이 정상적으로 작동합니다.
// Go to settings fragment
FragmentSettings mFragmentSettings = new FragmentSettings();
getFragmentManager().beginTransaction().replace(R.id.container, mFragmentSettings).commit();
문제는 내가 필요 버튼 앱이 조각을 대체하지 않습니다 클릭하면, 그것은 단지 이전을 통해 새로운 조각을 추가하는 것입니다, 그래서 그들은 축소 은 그 때 나는 버튼 클릭을 기반으로, 다른 조각을 추가 할 수 있습니다. 너 내가 여기서 뭘 잘못하고 있는지 말해 줄 수 있니?
편집 : 나는 이 같은 방법을 onOptionsItemSelected 내에서 에서 getSupportFragmentManager()를 사용하려고하면 다음에 "이 방법은 (INT, 조각)을 대체 :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
// Go to settings fragment
FragmentSettings mFragmentSettings = new FragmentSettings();
getFragmentManager().beginTransaction()
.replace(R.id.container, mFragmentSettings).commit();
}
return super.onOptionsItemSelected(item);
}
나는이 오류 유형 (FragmentSettings) 인수에 대해 FragmentTransaction 유형이 적용되지 않음 "
'onOptionsItemSelected (MenuItem item) {'메서드 내에서 두 번째 (바꾸기) 메소드를 사용합니다. 그리고'getSupportFragmentManager'를 호출하면 ** 인수 **에 **이 인수에 해당되지 않는다는 오류가 나타납니다. – Vla
@Vla 사용한 코드와 전체 오류 메시지를 게시하십시오. – Simas
내 게시물을 세부 정보로 업데이트했습니다. – Vla