2012-04-25 21 views
0

2つのレイアウトがあり、順番にそれを膨らませています。前のビューを閉じて別のレイヤーを展開したいのですが、ビューが背景に移動するため、両方のダイアログが表示されます。バックグラウンドにあるダイアログを閉じます。
私は以下の修正を試みました:前のレイアウトを閉じて別のレイヤーを閉じる

1.dialog.dismiss(); ---動作していません。

2.view.setVisibility(View.GONE); ---ダイアログのタイトルはまだダイアログと共に残っています。

私はコード全体を添付しています。この問題を解決する方法を教えてください。ありがとうございます。

menuproject.java

 package com.menuproject; 

     import android.app.Activity; 
     import android.app.AlertDialog; 
     import android.os.Bundle; 
     import android.view.LayoutInflater; 
     import android.view.Menu; 
     import android.view.MenuItem; 
     import android.view.View; 
     import android.view.View.OnClickListener; 
     import android.widget.Button; 

     public class menuproject extends Activity { 
      /** Called when the activity is first created. */ 

      AlertDialog.Builder dialog; 
      AlertDialog.Builder dialog2; 
      private AlertDialog alert = null; 
      private AlertDialog alert2 = null; 
      View updatedialog; 
      View updatedialog2; 

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

      } 

      protected void layoutsecond() { 
       // TODO Auto-generated method stub 
       this.dialog2 = new AlertDialog.Builder(this); 
       this.dialog2.setTitle("Update"); 

       LayoutInflater layoutInflater = LayoutInflater.from(this); 
       updatedialog2 = layoutInflater.inflate(R.layout.updatedialog2, null); 

       this.dialog2.setView(updatedialog2); 
       alert2 = this.dialog2.create(); 
       this.dialog2.show(); 

      } 

      @Override 
      public boolean onCreateOptionsMenu(Menu menu) { 
       // TODO Auto-generated method stub 
       MenuItem mi = menu.add(1, 1, 1, "My Menu1"); 
       mi.setIcon(getResources().getDrawable(R.drawable.icon)); 

       return super.onCreateOptionsMenu(menu); 
      } 

      @Override 
      public boolean onOptionsItemSelected(MenuItem item) { 

       switch (item.getItemId()) { 
       case 1: 

        layoutfirst(); 

        Button b = (Button) updatedialog.findViewById(R.id.Button11); 
        b.setOnClickListener(new OnClickListener() { 

         public void onClick(View v) { 
          // TODO Auto-generated method stub 

          // updatedialog.setVisibility(View.GONE); 

          // alert.dismiss(); 

          layoutsecond(); 

         } 
        }); 

        break; 

       } 
       return super.onOptionsItemSelected(item); 
      } 

      private void layoutfirst() { 
       // TODO Auto-generated method stub 

       this.dialog = new AlertDialog.Builder(this); 
       this.dialog.setTitle("Update"); 
       // this.dialog.setMessage(""); 

       LayoutInflater layoutInflater = LayoutInflater.from(this); 
       updatedialog = layoutInflater.inflate(R.layout.updatedialog, null); 

       this.dialog.setView(updatedialog); 
       alert = this.dialog.create(); 
       this.dialog.show(); 

      } 

     } 

main.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" 
     /> 
    </LinearLayout> 

updatedialog.xml

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/ScrollView02" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:fillViewport="true"> 

<LinearLayout 
    android:id="@+id/liner1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" 
    android:orientation="vertical" > 
     <requestFocus></requestFocus> 

     <Button 
      android:id="@+id/Button11" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawableLeft="@android:drawable/ic_menu_call" 
      android:text="Update Tel" /> 

     <Button 
      android:id="@+id/Button10" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawableLeft="@android:drawable/ic_menu_call" 
      android:text="Update Address" /> 

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

    </View> 

</LinearLayout> 
</ScrollView> 

updatedialog2.xml

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/ScrollView021" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:fillViewport="true"> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" 
    android:orientation="vertical" > 
     <requestFocus></requestFocus> 

     <Button 
      android:id="@+id/Button01" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:drawableLeft="@android:drawable/ic_menu_call" 
      android:text="Update Mobile" /> 

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

    </View> 

</LinearLayout> 
</ScrollView> 

答えて

0

代わりにalert.setContentView(inflated_layout)を試したことがありますか?dialog.setView(view_name)

+0

reply.Aboveのコードは動作しません。dialog.setContentView()メソッドは存在しません。 –

+0

alertdialogを使用していることを確認しました。それはあなたが使用しているAPIレベルです。 –

+0

AlertDialog.Builderダイアログ。ここのダイアログはAlertDialog.Builderです.APIレベルは8 android 2.2です。 –

関連する問題