Visual Studio 2015 - Xamarin - Android - Getting “

2020-02-25 22:29发布

Adding Additional Activity .cs and Layout axml Using Visual Studio 2015.

I'm very new to Xamarin and Android development, but have been a developer for a few years using VB and now C#. I have a simple app on Android 4.2 that is getting more complicated as I go along. The simple matter us that I want to add an additional GpsAction.cs and corresponding Gps.axml layout to the project. It seems impossible to find the right combination syntax to achive this. I have a mainActivity with main.axml. In VS 2015 it's very simple to add new but I keep getting "resource.id does not contain a definition for" I would really appreciate your help with this

namespace AddCam
{
[Activity(Label = "GpsActivity")]
public class GpsActivity : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.GpsLayout);

        string c = FindViewById<TextView>(**Resource.Id.textView1**).Text;
        // Create your application here
    }
}

16条回答
beautiful°
2楼-- · 2020-02-25 23:31

My problem was I was trying to debug Xamarin Android project (native) using Xamarin Live Player, connecting using USB cable and selecting my device for debugging solved the problem

查看更多
叼着烟拽天下
3楼-- · 2020-02-25 23:32

Cleared Main.axml page and Reset and it is working.

查看更多
仙女界的扛把子
4楼-- · 2020-02-25 23:34

Make sure your axml is well formed and rebuild the solution it should work, if you continue facing the same issue then remove axml and add it again then build the solution.

查看更多
Melony?
5楼-- · 2020-02-25 23:34

(VS 2019) I did the previous solutions and nothing, I had the same problem and the solution for me was to remove '&' from the text of TextView, I was trying to Set the text to "text&text" even &&(I though it was like mnemonics as in WindowsForms) didn't work so I had to remove it and it fixed.

查看更多
登录 后发表回答