귀하의 질문은 내가 대답을 생각합니다 모호 :에서
당신의 onOptionsItemSelected()
당신은 ID R.id.llPlay
으로 LinearLayout
를 검색하고 removeAllViews()
으로 모든 아이 뷰를 제거한 다음 R.layout.current_play
와 화면 레이아웃을 팽창 Button
과 함께 LinearLayout
(aktuelle_spiele
)을 가지며 TextView
(텍스트로 "Hallo"로 설정)도 있습니다. 문제는 레이아웃을 부 풀릴 때 그 순간에 그 레이아웃에있는 뷰만 팽창 시킨다는 것입니다. 당신이 당신의 레이아웃을 원하는 경우 또한 코드에서 구축 TextView
는 다음 두 가지 옵션이 있습니다 것을 포함합니다 : 그래서 당신이 나중에 검색 할 수 있습니다
1 직접 current_play.xml
레이아웃에 TextView
를 추가하고 또한에 ID를 추가를 TextView
(아 파크 - 그 findViewById(R.id.the_text)
) 및 텍스트에 "안녕"로 설정 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/aktuelle_spiele"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView
android:id="@+id/the_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
편집 :
이 동적으로 원하는 곳 레이아웃을 구축하지만 inflat에 대한 참조를 길게 에드 뷰.
LinearLayout ll = (LinearLayout) View.inflate(TabAndPlay.this, R.layout.current_play, null);
TextView tv = new TextView(TabAndPlay.this);
tv.setText("hallo");
tv.setBackgroundColor(Color.GRAY);
ll.addView(tv);
가 그 부풀려 ll
에 대한 참조를 유지하고 기본 레이아웃에 onOptionsItemSelected()
콜백에 전달 :이 같은 뷰 생성한다면,
case R.id.current_play:
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.llPlay);
mainLayout.removeAllViews();
mainLayout.add(ll);
return true;
감사를 추가하는 동안,하지만 직접 current_play에 내가 동적 textviews를 얻을 수 있기 때문에 얻을니까. 하나 이상의 레이아웃을 동적으로 (디스플레이가 아닌) 만들고 사용자가 메뉴 (R.id.current_play)를 선택하는 것보다 레이아웃을 표시하고 싶습니다 ... – StefMa
@IceClaw 다음 옵션 2는 당신. 내 대답을 업데이트했습니다. – Luksprog