Project build error in xamarin studio - c#

While building project an error is shown and build getting failed.
Error redirects to axml file below:
<?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">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView" />
</LinearLayout>
Error :
C:\Users\Documents\Projects\\\Resources\layout\Main.axml(1,1): Error CS0116:
A namespace cannot directly contain members such as fields or methods (CS0116)
(ABC)

Check the Build Action for the Main.axml file. It should be set to Android Resource but it sounds like it is set to Compile.
Right click the Main.axml file and use the Build Action menu to change this.

Related

MaterialSpinner label/hint not showing when running the app

The materialspinner is not showing any hints or labels.
This is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://shcemas.android.com/apk/res-auto"
android:orientation="vertical"
android:minWidth="300dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fr.ganfra.materialspinner.MaterialSpinner
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/eventnameSpinner"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelText="Select Event"
app:ms_hint="Select Event"
app:ms_alignLabels="true"/>
<fr.ganfra.materialspinner.MaterialSpinner
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/eventpackageSpinner"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelText="Select Package"
app:ms_hint="Select Package"
app:ms_alignLabels="true"/>
</LinearLayout>
With the code
app:ms_floatingLabelText="Select Package"
app:ms_hint="Select Package"
it is supposed to show when running the app, instead it only shows the content inside it. It is supposed to show a hint "Select Event" and "Select Package" for both spinners but it did not, and when clicking the spinner, the label would hover on top same as the EditTexts. Is there something missing?
This is the layout
Are you using nuget Nivaes.Droid.Ganfra.MaterialSpinner,right?
I found that this nuget hasn't been updated for several years and is not recommended.
But you can use Xamarin.Android Spinner as an alternative.
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/planet_prompt"
/>
Similarly, when setting property prompt, the spinner does not display the value of prompt.
But when we set property style="#android:style/Widget.Spinner" for spinner, if we set data resource for the Spinner and click the Spinner, the prompt will display in a dialog.
<Spinner
style="#android:style/Widget.Spinner"
android:tooltipText="abc"
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/planet_prompt"
/>
Of course, you can also add a TextView to display the prompt,just as document Xamarin.Android Spinner says.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="#string/planet_prompt"
/>
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/planet_prompt"
/>
Note:
You can check the following threads for more ideas:
How to make an Android Spinner with initial text "Select One"?
Spinner prompt not showing

Xamarin - Image Not Displaying

I'm trying to display an image in my Xamarin app but it does not seem to be displaying on the screen. The app complies and runs without any warnings or errors, and a separate image is displaying successfully as a long toolbar along the top of the app.
The images are held within my Resources -> Drawable directory.
XAML
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:minWidth="25px"
android:minHeight="25px"
android:rowCount="5"
android:columnCount="2">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_height="150px"
android:layout_width="match_parent" />
<ImageView
android:id="#+id/cardOne"
android:layout_width="wrap_content"
android:layout_height="150px"
android:src="#drawable/m1"
android:layout_row="3"
android:layout_column="1" />
</GridLayout>
MainActivity
var imageView = FindViewById<ImageView>(Resource.Id.cardOne);
imageView.SetImageResource(Resource.Drawable.m1);

Visual studio, Xamarin, WebView

I'm making application for android using Visual Studio and Xamarin but I have problem with WebView when I create a WebView and try to see it in android emulator i get an error:
Android.Views.InflateException: Binary XML file line #1: Error inflating class android.webkit.WebView
Anybody knows where is problem?
The Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="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">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView1" />
</LinearLayout>
After trying out the Layout xml the compiler throws an error becouse of a semicolon at the end of xmlns:android="schemas.android.com/apk/res/android";. If you remove that the layout should build.
Another thing is that the url in xmlns:android attribute is missing http:// in front of the url. Without that the inflater doesn't understand the attributes correctly.
Here is a fixed Layout for you
<?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">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView1" />
</LinearLayout>

Monofor droid VS 2012 navigate to another page using button

Here is the problem right now.
create a simple axml file
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">
<Button
android:id="#+id/MyButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Hello" />
</LinearLayout>
and here is the register.axml file
<?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">
<EditText
android:id="#+id/registerID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="70dp"
android:hint="ID" />
</LinearLayout>
i searched a lot at this forum but what i found the code was in java.
and im using c# in VS2012 to do so.
and i searched a lot internet and failed to find for it.
can anyone give some idea ?
Just like with Java Android, Xamarin.Android uses both Activities and Fragments for displaying content and navigation.
The most simple sample would be that you create two Activities. One Main Activity, with you first layout, and a second one with your register.axml layout.
The button in the Main Activity, has a Click event, which you can do whatever you want, when it is clicked, i.e. start the second Activity. This can be done with an Intent, which Android uses i.e. for navigation:
var button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += (s, e) => {
var intent = new Intent(this, typeof(SecondActivity));
StartActivity(intent);
};
I recommend you to read the documentation Xamarin has, which goes through these basic things.

Android Layout issues.. Not sure how to debug

UPDATE____
Logcat output http://pastie.org/2039452
My application is stopping in the debugger, and then crashing on this line, but it is strange because it has no error information just a green arrow like so...
Any insight on what this arrow means in general would be appreciated...
Here is LayoutStudentList
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<TextView
android:id="#+id/studentHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:text="#string/StudentListHeader"
android:layout_alignParentTop="true"
/>
<EditText
android:id="#+id/studentSearch"
android:layout_width="fill_parent"
android:layout_below="#id/studentHeader"
android:padding="10dp"
android:textSize="12sp"
android:editable="true"
android:hint="#string/StudentFilterPlaceholder"
/>
<ListView
android:id="#+id/studentListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/studentSearch"
android:padding="10dp"
/>
</RelativeLayout>
The problem is almost definitely in my XML somewhere, as when I replace the layout contents with a single textview and set the text it works fine.
The problem is that the studentSearch EditText element in your layout file didn't specify a layout_height attribute. Once you add that in the problem should go away (I verified this locally as well). The error message and accompanying stacktrace would also be visible via the ADB logcat output:
I/dalvikvm( 2083): Ljava/lang/RuntimeException;: Binary XML file line #14: You must supply a layout_height attribute.
What does 'hanging' mean? Like, stopped in the debugger? Crashing?
Shouldn't that be setContentView(), not Set with a capital S? Maybe that's the problem.

Categories