2

In Xamarin, I create an EditText Field and a Search Button, when a user taps the button on their Android device, it must search the Azure database tables, find the relevant record and display/populate it in the record_view.axml I created?

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:text="ID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Id_row"
        android:layout_weight="1"
        android:gravity="center"
        android:textSize="15dp"
        android:textColor="#ffffffff"
        android:textStyle="bold" />
    <TextView
        android:text="Name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Name_row"
        android:layout_weight="1"
        android:textSize="15dp"
        android:textColor="#ffffffff"
        android:textStyle="bold" />
    <TextView
        android:text="Mobile"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Mobile_row"
        android:layout_weight="1"
        android:textSize="15dp"
        android:textStyle="bold"
        android:textColor="#ffffffff"
        android:gravity="center" />
    <TextView
        android:text="Email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/Email_row"
        android:layout_weight="1"
        android:textSize="15dp"
        android:textStyle="bold"
        android:textColor="#ffffffff"
        android:gravity="center" />
</LinearLayout>

I have the same rows above in the Azure database as columns.

Can anyone point me in the right direction, a tutorial or some info regarding this will really help?

Thanks in advance

1 Answer 1

1

I'd recommend checking out this and this.

Here is a small example, showing how you can use Where() to filter your tables:

public async Task<List<Person>> Search()
{
    // you'd access your xml here
    TextView nameTextView = null;

    // using real keys
    MobileServiceClient client = new MobileServiceClient(AppUrl, AppKey);

    // and real data objects
    IMobileServiceTable<Person> personTable = client.GetTable<Person> ();

    // just to keep things clean, an interstitial var
    string name = nameTextView.Text;

    // use LINQ to filter on the properties we care about
    // you can add && p.Blah == whatever, as much as you'd like
    return await personTable.Where (p => p.Name == name).ToListAsync();
}

Additionally, Azure lets you define custom APIs, one of which may make your searching easier, if you'd like to make it fuzzy, and so on.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Josh, can I use the 'where' function with an 'if' statement. When the user types in a search field and clicks search? I'm not too sure why I'm finding this so difficult,however I am new to Xamarin and Azure, I usually figure it out after testing a bit, not this time though.
Not working correctly. public async List<PrecinctData> Search() gives error - The return type of an async method must be void, Task or Task<T>
Also getting error on these lines, MobileServiceClient client = new MobileServiceClient(AppUrl, AppKey); (the type 'system.net.http.httpmessagehandler' is definedin an assembly that is not referenced, you must add a reference to the assembly. Also on last line it says cannot implictly convert type system.collections.generic.list <appname.personData> to appname.personData.
Yeah, I just quickly banged that out. you'll want to return Task<List<PrecinctData>>, as it is awaitable. And there is an error on the new Client line because it's being instantiated with 2 random variables I made up, AppUrl and AppKey. You'll want to replace that with your actual url / key from Azure. And probably not make the client in the method anyway, this was merely meant to illustrate that you can .Where() on a table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.