0
我有一個簡單的開始Android應用程序是這樣的:所有代碼後活動的setContentView調用不執行(無異常或消息)
(下面的所有文字代碼)
的代碼永遠不會命中第一個斷點。如果我在this.SetContentView(...)
調用上放置了一個斷點,它將會觸發(但仍然不會觸發調用btnStart行)。另外,當我點擊按鈕時,什麼也沒有發生。也不會拋出異常。
我做錯了什麼?
EDIT:我做1個步驟進一步,加入這行代碼右接收btnStart
後:
btnStart.Text = "Abc";
它不是太執行。我知道,在SetContentView
之後,代碼不再執行了!
代碼MainActivity.cs:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
this.SetContentView (Resource.Layout.Main);
var btnStart = this.FindViewById<Button>(Resource.Id.btnStart);
btnStart.Click += (sender, e) =>
{
var txtContent = this.FindViewById<EditText>(Resource.Id.txtContent);
var content = txtContent.Text;
txtContent.Text = "Hello " + content;
};
}
佈局main.axml:
<?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="match_parent">
<Button
android:text="Start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnStart" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtContent" />
</LinearLayout>
你有沒有嘗試清理你的項目,然後重建?嘗試看看是否有任何幫助 – apineda
@apineda是的,我做到了。清潔解決方案 - >重建解決方案。還是一樣。 –
你能否分享一個可以重現問題的基本演示? –