2013-11-20 30 views
0

當我把在同一活動第二佈局不顯示列表視圖,唯一的按鈕和滾動的Android第二的setContentView發射使用按鈕和不顯示列表視圖

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    >  
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="488dp" 
     android:id="@+id/scrollView" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="3dp" > 
     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="match_parent" 
      android:layout_height="453dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:imeOptions="actionNext" />  
    </ScrollView> 
    <Button 
     android:id="@+id/btinicio" 
     android:layout_width="153dp" 
     android:layout_height="60dp" 
     android:text="@string/bt1text" 
     android:onClick="hagotest" 
     android:layout_gravity="center|bottom" 
     android:longClickable="false" 
     android:singleLine="false" 
     android:textSize="@dimen/activity_horizontal_margin" 
     android:textStyle="bold" /> 
     </LinearLayout> 

事件與點擊按鈕激發

 public void hagotest (View v) 
    { 
     setContentView(R.layout.test_view); 
     tv2 = (TextView)findViewById(R.id.textView2); 
     String s = ""; 
     s += " Una sola opcion por linea, pasar el dedo sobre el texto para continuar"+"\n"; 
     tv2.setText(s); 
     tv2.setTextColor(Color.RED); 

     listView = (ListView) findViewById(R.id.lw); 
     adapter =new ItemAdapter(this,ArrayItem); 
     listView.setAdapter(adapter); 


     llenolista(); 
     bt1= (Button) findViewById(R.id.btlimpio); 
     bt2= (Button) findViewById(R.id.btResultado); 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
} 


<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" > 
      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="match_parent" 
       android:layout_height="30dp" 
       android:imeOptions="actionNext" 
       android:textSize="12dip" 
       android:layout_alignParentRight="true" 
       /> 


     <ListView 
      android:id="@+id/lw" 
      android:layout_width="wrap_content" 
      android:layout_height="216dp" 
      android:layout_gravity="center" 
      android:textAlignment="textStart" 
      style="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small" 
      android:fastScrollAlwaysVisible="true" 
      android:fastScrollEnabled="true" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="5.0sp" 
      android:paddingLeft="15dp" 
      android:paddingBottom="4dp" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <Button 
      android:id="@+id/btlimpio" 
      android:layout_width="171dp" 
      android:layout_height="wrap_content" 
      android:text="@string/bt2txt" 
      android:onClick="hagolimpieza" 
      android:layout_gravity="center|left" 
      android:longClickable="false" 
      android:singleLine="false" 
      android:textSize="@dimen/activity_horizontal_margin" 
      android:layout_centerVertical="true" 
      android:layout_alignParentLeft="true" /> 

     <Button 
      android:id="@+id/btResultado" 
      android:layout_width="171dp" 
      android:layout_height="wrap_content" 
      android:text="@string/bt3txt" 
      android:onClick="resultado" 
      android:layout_gravity="center|right" 
      android:longClickable="false" 
      android:singleLine="false" 
      android:textSize="@dimen/activity_horizontal_margin" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" /> 
    </RelativeLayout> 


</LinearLayout> 

this is listitems 


<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 


    <TextView 
     android:id="@+id/tvPregunta" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:singleLine="true" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textIsSelectable="false" 
     android:textSize="12dip" 
     android:layout_alignParentLeft="true" 
       /> 


    <CheckBox 
     android:id="@+id/tvSiempre" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/tvPregunta" 
     android:focusable="false" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:focusableInTouchMode="false" 
     android:textSize="10dip" 
     android:text="" 
     android:layout_alignBottom="@id/tvPregunta" 
     android:onClick="ckCHEck" 
     android:tag="" 
    /> 

    <CheckBox 
     android:id="@+id/tvOcasio" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/tvSiempre" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textSize="10dip" 
     android:text="" 
     android:layout_alignBottom="@id/tvPregunta" 
     android:onClick="ckCHEck" 
     android:tag="" 
     /> 

    <CheckBox 
     android:id="@+id/tvNunca" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/tvOcasio" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textSize="10dip" 
     android:text="" 
     android:layout_alignBottom="@id/tvPregunta" 
     android:onClick="ckCHEck" 
     android:tag="" 
     />  
</RelativeLayout> 

我需要點擊按鈕時顯示此
enter image description here

回答

0

setContentView()不應該叫做mor比一次。如果你想動態添加不同的佈局,你應該考慮使用Fragments

相關問題