2012-06-04 2 views

답변

2

ContentView는 하나의 활동에만 포함됩니다.

Activity으로 확장한다고 가정하면 콘텐츠보기를 설정 한 후에보기에 액세스 할 수 있습니다. 당신이 대화에 있다면

Button homeButton = (Button) findViewById(R.id.homeButton); 
homeButton.setText(); homeButton.setOnClickListener() etc 

, 또는 특정 상황에서 특정 뷰에 액세스해야하거나 의도에있어 및 주요 활동의에 물건을 액세스 할 필요가 : 당신이 당신의 레이아웃에 버튼이 말 레이아웃 :

Button secondButton = (Button) getActivity().findViewById(R.id.secondButton); 
//other methods on the button 

EDITS--

음 이미지는, 당신은 단지 레이아웃에 이미지 뷰를 추가

<ImageView android:id="@+id/logoImageView" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:src="@drawable/logo" android:contentDescription="@string/app_name" 
     android:layout_gravity="center_horizontal"/> 

코드로 특별히 작업 할 필요가 없습니다. 코드가 표시되어야합니다.

단추 및 다른보기를 XML을 통해 추가 할 수도 있습니다. 프로그래밍 방식으로 항목을 추가 할 수도 있지만 일반적이지는 않습니다. 내가 제대로 생성자는 XML 파일에없는 자바에있는 버튼을 만들 기억한다면

, 그것은 Button aNewButton = new Button(getApplicationContext()); aNewButton.setText("whatever");

+0

레이아웃에 물건을 그리려면 어떻게해야합니까? 아직 거기에없는 단추 또는 이미지. – kaid

+1

내 응답을 편집 했으므로 – Davek804

+0

을보십시오. 런타임 전에 XML의 모든 UI 요소를 만들고 런타임 중에 조작해야합니다. – kaid

관련 문제