0

我在AlertDialog工作中遇到了一些困難。我有六個按鈕,當每個按鈕被點擊時,AlertDialog框應顯示其內容。即使prg運行時沒有任何錯誤,並且如果我點擊一個按鈕對話框不打開任何人都可以幫我解決tat片段頁打開的按鈕?提前致謝。AlertDialog分段

這裏是我的片段活動代碼:

@TargetApi(Build.VERSION_CODES.HONEYCOMB) 
public class Fragment3 extends DialogFragment implements OnClickListener { 

    private static final int ALERT_DIALOG1 = 1; 
    private static final int ALERT_DIALOG2 = 2; 
    private static final int ALERT_DIALOG3 = 3; 
    private static final int ALERT_DIALOG4 = 4; 
    private static final int ALERT_DIALOG5 = 5; 



    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     //setContentView(R.layout.activity_fragment2); 
    View view = inflater.inflate(R.layout.fragment3layout, container, false); 

     Button alert1 = (Button) view.findViewById(R.id.Button1); 
     alert1.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View view) { 
      showDialog(ALERT_DIALOG1); 
     } 
    }); 



default: 
     dialog = null; 
    } 
    return dialog; 

} 

這裏是我的清單文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.pacificstereoapp" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="16" /> 


      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.example.a.Fragment1" 
      android:label="@string/title_activity_fragment1" > 
     </activity> 

    </application> 

</manifest> 
+0

dialog.show()行缺少 – Riskhan 2013-02-15 06:14:16

+0

您必須添加您的警報特定的代碼只沒有必要在這裏加入了全碼 – NetStarter 2013-02-15 06:22:23

回答

1

你正在創建對話框,但沒有真正顯示它。致電dialog.show()

+0

我增加了dialog.show(),如下 公共無效的ShowDialog(中間體alertDialog1){ \t \t // TODO自動生成方法存根 \t對話框對話框= onCreateDialog(alertDialog1); \t dialog.setOwnerActivity(this.getActivity()); \t dialog.show(); \t} 但得到這個錯誤 窗口管理器$ badtokenexception 在取代'建設者=新AlertDialog.Builder(this.getActivity()getApplicationContext()。)logcat的 – user2028018 2013-02-15 06:38:37

+0

;',用'建設者=新AlertDialog.Builder( this.getActivity());' – Rajesh 2013-02-15 07:10:36

+0

非常感謝Rajesh。改變它後... :) – user2028018 2013-02-15 07:17:05