1849698465 by Unknown
Author:Unknown
Language: rus
Format: mobi
Published: 2014-02-07T13:30:48+00:00
XamChat for Android
So if we compile and run the application, we can navigate to a fully implemented friends list screen, as shown in the following screenshot:
Composing messages
The next screen is a bit more complicated; we will need to create a ListView that uses multiple layout files for each row, depending on the type of the row. We'll also need to perform some layout tricks to place a view below the ListView and set up ListView to autoscroll.
For the next screen, let's begin by creating a new layout named Messages.axml in the layout folder of the Resources directory and then perform the following steps: 1. Drag a new ListView onto the layout. Set Id to @+id/messageList.
2. Check the box for Stack From Bottom and set Transcript Mode to alwaysScroll. This will set it up to display items from the bottom up.
3. Set the Weight value to 1 for ListView in the Layout tab under the LinearLayout section.
4. Drag a new RelativeLayout control onto the layout. Let Id be the default value, or remove it.
5. Drag a new Button control inside RelativeLayout. Set Id to @+id/
sendButton.
6. Check the box for Align Parent Right in the Layout tab.
7. Drag a new Plain Text control found in the Text Field section inside RelativeLayout to the left of the button. Set Id to @+id/messageText.
8. In the Layout tab, set To Left Of to @+id/sendButton, and set Width to match_parent.
9. Check the box for Center in Parent to fix the vertical centering..
[ 126 ]
Chapter 6
When completed, the XML file will be as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/messageList"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" />
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="Send"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sendButton" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/sendButton"
android:layout_centerInParent="true"
android:id="@+id/messageText" />
</RelativeLayout>
</LinearLayout>
Next, perform the following steps to make two more Android layouts: 1. Create a new layout named MyMessageListItem.axml in the layout folder of the Resources directory.
2. Open the layout and switch to the Source tab. Change the root XML element to a RelativeLayout.
3. Switch back to the Content tab and drag two TextView controls onto the layout.
[ 127 ]
XamChat for Android
4. In the Id field, enter @+id/myMessageText and @+id/myMessageDate respectively.
5. For both the views, set Margin to 3dp, and Width and Height to wrap_content.
6. For the first TextView, set Color under the Style tab to @android:color/
holo_blue_bright.
7. For the second TextView, check the Align Parent Right checkbox under the Layout tab.
8. Create a new layout named TheirMessageListItem.axml and repeat the process. Select a different color for the first TextView in the new layout.
Finally, we'll need to create a new activity for the screen. Create a new Android Activity named MessagesActivity.cs in the Activities directory. Begin with the standard code to set up an activity as follows:
[Activity(Label = "Messages")]
public class MessagesActivity : BaseActivity<MessageViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
}
}
Next, let's implement a more complicated adapter than we implemented earlier, as follows:
class Adapter : BaseAdapter<Message>
{
readonly MessageViewModel messageViewModel =
ServiceContainer.Resolve<MessageViewModel>();
readonly ISettings settings =
ServiceContainer.Resolve<ISettings>();
readonly LayoutInflater inflater;
const int MyMessageType = 0, TheirMessageType = 1;
public Adapter (Context context)
{
inflater = (LayoutInflater)context.GetSystemService (
Context.LayoutInflaterService);
}
public override long GetItemId(int position)
{
return messageViewModel.Messages [position].Id;
}
[ 128 ]
Chapter 6
public override int Count
{
get { return messageViewModel.Messages == null ? 0
: messageViewModel.Messages.Length; }
}
public override Message this[int index]
{
get { return messageViewModel.Messages
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Becoming Supernatural by Dr. Joe Dispenza(8226)
Crystal Healing for Women by Mariah K. Lyons(7936)
The Witchcraft of Salem Village by Shirley Jackson(7280)
Inner Engineering: A Yogi's Guide to Joy by Sadhguru(6800)
The Four Agreements by Don Miguel Ruiz(6770)
The Power of Now: A Guide to Spiritual Enlightenment by Eckhart Tolle(5790)
Secrets of Antigravity Propulsion: Tesla, UFOs, and Classified Aerospace Technology by Ph.D. Paul A. Laviolette(5374)
The Wisdom of Sundays by Oprah Winfrey(5168)
Room 212 by Kate Stewart(5130)
Pale Blue Dot by Carl Sagan(5013)
Fear by Osho(4743)
The David Icke Guide to the Global Conspiracy (and how to end it) by David Icke(4724)
Animal Frequency by Melissa Alvarez(4478)
Rising Strong by Brene Brown(4468)
How to Change Your Mind by Michael Pollan(4361)
Sigil Witchery by Laura Tempest Zakroff(4250)
Man and His Symbols by Carl Gustav Jung(4143)
Real Magic by Dean Radin PhD(4134)
The Art of Happiness by The Dalai Lama(4133)