2012-05-01 1 views
0

어제 나는 안드로이드 용 책상 시계를 만들었습니다. 이것을 위해 RelativeLayout을 만들어 시간, 분 등을 표시하고 옵션 정보 및 종료를 표시하는 메뉴를 만들었습니다. 글쎄, 모두 정상적으로 작동하지만 옵션을 클릭하면 문제가 발생합니다. 로그 캣이 보여줍니다어버이의 부모에게 removeView()를 호출합니다.

그래서 나는 당신이 날 도울 수 있기를 바랍니다

E/AndroidRuntime(14751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iamaner.T2Speech/com.iamaner.T2Speech.FrmAbout}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

... 필자가이 코드에 대해 들어,하지만 난 그것을 넣어하는 방법과 위치를 잘 모릅니다, 나는이 확인 될 것이라고 생각하지만

여기

final RelativeLayout fondo = (RelativeLayout)findViewById(R.id.your_layout);((RelativeLayout)fondo.getParent()).removeView(fondo); //scrollView.removeView(scrollChildLayout);

는 매니페스트 파일 내가 그 문제를 생각한다없는 것 같다, 내가 여기 FrmAbout 코드

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:name=".TimeToSpeechActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="landscape" 
     android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <activity android:name=".FrmAbout" /> 
</application> 

을 그리고 : 잘 모릅니다

public class FrmAbout extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.frmabout); 

    TextView txtVersion = (TextView)findViewById(R.id.Txtversion); 
    TextView txtWarning = (TextView)findViewById(R.id.Txtwarning); 
    TextView txtInstructions = (TextView)findViewById(R.id.Txtinstructions); 
    TextView txtContact = (TextView)findViewById(R.id.Txtcontact); 

    setContentView(txtVersion); 
    setContentView(txtWarning); 
    setContentView(txtInstructions); 
    setContentView(txtContact); 

    } 
    } 

좋아, 그것을 해결 .... 문제가 있었다 된 setContentView() 메소드를, 그것을 삭제하고 지금은 작동

+1

시도해보십시오. ((ViewGroup) scrollChildLayout.getParent()). removeallViews();이 답변에서 제안했습니다. http://stackoverflow.com/questions/6526874/call-removeview-on-the-childs-parent-first –

답변

0

코드에서 나는 활동을 호출하기 전에 모든보기를 제거하는 이유를 이해하지 못했습니다. 새로운 활동을 시작하기 때문에 모든보기를 제거 할 필요가 없기 때문에 이것이 요구 사항입니까? 현재 활동에서 뷰를 제거하지 않고 startActivity (intent)를 직접 호출 할 수 있습니다.

문제를 이해할 수 있도록 로그를 게시하십시오.

+0

Ok, 편집하고 logcat 오류를 추가했습니다. 왜냐하면 logcat은 FrmAbout을 시작하기 전에 removeView()를 호출해야한다고 말하기 때문입니다 ... – BamsBamx

0

이 질문은 다음 번에 검색을 사용해보십시오. Take a look at the answer here, 내 코드에서 사용하고 잘 작동합니다.

+0

감사합니다. 나는 당신이 게시 한 것을 찾았지만, 나는 그것을 놓아야 만하는지 모른다. 어쩌면 첫 번째 코드에서 ??? 이게 괜찮을 거라고 생각하세요 ??? 마지막으로 RelativeLayout fondo = (RelativeLayout) findViewById (R.id.your_layout);'((ViewGroup) fondo.getParent()). removeView (fondo);' – BamsBamx

관련 문제