Wednesday, November 27, 2013

GET SELECTED ITEMS FROM LISTVIEW IN ANDROID USING VS2012

XAMARIN – GET SELECTED ITEMS FROM LISTVIEW IN ANDROID

NOV 28, 2013
 
 
 
 
 
 
Rate This

In this post we would see, how to get the selected items from the screen activity where a list of options are displayed.

The following is the layout for displaying the Multiple Selectable ListView with a button.

Now we would bind data to the ListView.
Also we would make it Multiple Selectable with SelectOption as Multiple.
And we would subscribe to the click event of the Button.

In the button click event handler, we would do as following to get the selected data out of ListView.

ShowAlert is a helper method to show alerts with easy, here is the code for that too.

Now run the application. You could see the fixed

As on button click, the selected items positions with respect to the collection is displayed.

Hope this post helps, thanks for Reading.

Full Source Code: Click Here

SELECTIVE LISTVIEW IN ANDROID USING VS2012

XAMARIN – SELECTIVE LISTVIEW IN ANDROID

 
 
 
 
 
 
1 Votes

In this post we would see how to display a collection in ListView and select one or many items.
As we are going to have a ListView, the following is the simple layout.

Now instead of creating a layout for the ListView content, we would use some from the Android.Resource . And adding the ChoiceMode property to the ListView.

Here is the view, with single selection mode with Radio Buttons.

We have a CheckBox style instead of RadioButton, here are the changes.

And you would get the Check image instead of the RadioButton.

Now, let’s try for the multiple selections. Also you need to change the ChoiceMode to Multiple.

And you would get the multiple checked items.

Hope this post helps, thanks for reading.
Full Source Code: Click Here

DISPLAY FIXED LAYOUT AT THE BOTTOM IN ANDROID USING VS2012

XAMARIN – DISPLAY FIXED LAYOUT AT THE BOTTOM IN ANDROID

 
 
 
 
 
 
Rate This

In some design scenarios, where we would require a fixed layout at the bottom of the screen. The fixed layout may contain a set of controls. In this post, we would see how do we do that.
Here is a sample layout with ListView.
As you see in above image, the last control before the Fixed Layout, should have the above properties with values.
Now, the Linear Layout would become fixed at the bottom, once you apply the style of ButtonBar.
Now the Button inside it, is the content of the fixed layout.
Hope this quick post helps, thanks for reading.
The following is the xml for your reference.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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">
 
<ListView
 
android:layout_width="fill_parent"
 
android:layout_height="0dp"
 
android:layout_weight="1"
 
android:id="@+id/listView1" />
 
<LinearLayout
 
style="@android:style/ButtonBar"
 
android:orientation="horizontal"
 
android:layout_width="fill_parent"
 
android:layout_height="wrap_content">
 
<Button
 
android:text="Done"
 
android:layout_width="fill_parent"
 
android:layout_height="fill_parent"
 
android:id="@+id/button1" />
 
</LinearLayout>
 
</LinearLayout>