4 Replies - 573 Views - Last Post: 19 December 2018 - 07:42 PM

#1 CampNerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-December 18

Drag and Drop is not working in Xamarin Android

Posted 11 December 2018 - 10:57 AM

ok I am new to mobile development. I primarily use WinForms and WPF in C#. Today I started to get in to the mobile development. I have followed a few tutorials and I ran in to a problem. When I drag a button from the toolbox, it will place in the top left hand corner. When I pull anything else, i.e.,. text, button... It will go to the exact same point the first button was placed. I can not place the new item underneath the previous.

So I am seeing all these tutorials on Xaramin Android Blank App tutorials and the drag and drop works perfect for them. So my question is: Why is the drag and drop not working in relation to where I want the items placed. I have attached a screen shot. The screen shot has two buttons layered, and the button below the two layered can only be placed where the other two buttons are placed.

This is the same with text as well. Do I need to reinstall the Mobile Dev components within visual studio?

I am new to Xaramin so if am doing something wrong please info me.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Drag and Drop is not working in Xamarin Android

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15058
  • View blog
  • Posts: 60,127
  • Joined: 12-June 08

Re: Drag and Drop is not working in Xamarin Android

Posted 11 December 2018 - 11:01 AM

Are you using the 'designer'?
https://docs.microso...cs?tabs=windows
Was This Post Helpful? 0
  • +
  • -

#3 CampNerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-December 18

Re: Drag and Drop is not working in Xamarin Android

Posted 11 December 2018 - 12:37 PM

i am using the designer, however after a few hours of searching yesterday and today. I finally found a post on stackoverflow explaining that Circular Dependencies cannot exist in a
RelativeLayout
. So I would have to use a
LinearLayout
wich corrected the problem, but then I got another problem I am trying to figure out with the
android:id="@+id/btnAdd"
and a few others.

Also the tutorials I am following has total different structures. So I am not sure if this goes back to the original problem with the mobile development needs to be reinstalled.

I am doing this tutorial https://www.youtube....h?v=5CgQUbnf1Qk actual coding begins at 13:00 (minute) and this is what my code looks like.

activity_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="fill_parent"
	android:layout_height="fill_parent"
	android:minWidth="25px"
	android:minHeight="25px"
	<TextView
		android:text="0"
		android:textSize="100sp"
		android:gravity="center"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:id="@+id/txtNumber"
		android:layout_marginTop="50dp"
		android:layout_marginBottom="50dp" />
	<Button
		android:text="Add"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:id="@+id/btnAdd"
		android:layout_marginTop="20dp"
		android:layout_marginBottom="50dp" />
	<Button
		android:text="Subtract"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:id="@+id/btnSubtract" />
	<Button
		android:text="Clear"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:id="@+id/btnClear"
		android:layout_marginTop="50dp" />
	
	</LinearLayout>




MainActivity.cs

using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;


namespace App1
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
    public class MainActivity : AppCompatActivity
    {
        TextView txtNumber;
        int number;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            txtNumber = FindViewById<TextView>(Resource.Id.txtNumber);

            FindViewById<Button>(Resource.Id.btnAdd).Click += (o, e) =>
            txtNumber.Text = (++number).ToString();

            FindViewById<Button>(Resource.Id.btnSubtract).Click += (o, e) =>
           txtNumber.Text = (--number).ToString();
        }
    }
}


however the id for the names of the buttons are not recognized it gives the
Resource.Id
does not contain a definition. So I am at a point of reinstalling everything, however if that does not work, then I don't know what to do.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#4 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: Drag and Drop is not working in Xamarin Android

Posted 19 December 2018 - 04:12 PM

CampNerd
try completely deleting the resourcedesigner.cs file from your computer then rebuild the solution and add existing item > resourcedesigner.cs readd the resourcedesigner to project

syntax looks correct but the FindViewById<> method in Xamarin is completely jenk

it's not enough to remove it from the project you have to make sure it's completely off the computer then rebuild a new file and add existing
Was This Post Helpful? 0
  • +
  • -

#5 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: Drag and Drop is not working in Xamarin Android

Posted 19 December 2018 - 07:42 PM

another thing to mention is that you should make copies of your project frequently. Xamarin is extremely flaky and sometimes errors will pop out of nowhere and be un-fixable. There are reports of this all over the internet, so it's not just me.

Keep backup versions of compileable versions with alarming regularity.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1