所以我想在我的Activity中創建一個小的彈出選項菜單。我已經有了這個代碼,顯示菜單使開關按鈕(它位於AlertDialog中)在狀態更改時執行某些操作
public void ShowOptionsDialog()
{
Android.Support.V7.App.AlertDialog.Builder optionDialog = new Android.Support.V7.App.AlertDialog.Builder(this);
optionDialog.SetTitle("Optionen");
optionDialog.SetView(Resource.Layout.Options);
optionDialog.Show();
}
Resource.Layout.Options包含以下內容:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<android.support.v7.widget.SwitchCompat
android:id="@+id/previewSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:hint="Preview der Dokumente anzeigen"/>
</LinearLayout>
究竟是如何做的,我告訴應用程序做一些事情時按下開關時(開關)?
您快速。 ;-) –
已經嘗試過類似你的建議是什麼,當我用你的代碼中,我得到了同樣的錯誤了一句:「System.NullReferenceException:對象不設置到對象的實例」 但我不明白爲什麼。 .. – fbueckle
我現在得到這個錯誤: Java.Lang.NullPointerException:試圖調用空對象引用的接口方法'int java.lang.CharSequence.length()' :/ – fbueckle