MvxSpinner item should be blank until not select from dropdown list - xamarin.android

I'm using MvxSpinner and just want to show drop down selected value over spinner.Currently its showing first item from dropdown list but i want to show blank as i didn't choose any value from dropdown.
Spinner
<MvvmCross.Binding.Droid.Views.MvxSpinner
android:id="#+id/mySpinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxDropDownItemTemplate="#layout/myspinner_item"
local:MvxItemTemplate="#layout/myspinner_item"
android:layout_marginLeft="0dp"
android:dropDownWidth="257dp"
android:dropDownSelector="#drawable/list_item_selector"
android:layout_centerInParent="true"
android:spinnerMode="dropdown"
local:MvxBind="ItemsSource MyItems; HandleItemSelected SelectCommand" />
myspinner_item
<?xml version="1.0" encoding="utf-8"?>
<MvvmCross.Binding.Droid.Views.MvxLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_item_selector"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="32dp"
android:textSize="15sp"
android:textColor="#de000000"
android:lineSpacingExtra="5sp"
android:singleLine="true"
android:text=""
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_marginLeft="24dp"
local:MvxBind="Text Description; Typeface StringToFont('Effra_Rg')" />
</MvvmCross.Binding.Droid.Views.MvxLinearLayout>

It's showing the first item because it's bound to the item list. Might be considered bad practice by some, but if your goal is for it to stay blank until chosen, have you tried adding a new item to the front of your list with a blank description?

Related

antd menu icons API not working. Does not render

im trying to render a a side menu with a submenu , however i soon realize that the icon api is not working:
<Menu.Item key="1" >
<HomeOutlined />
<span>Home</span>
<Link to='/' />
</Menu.Item>
This is one of the menu items , it renders correctly if i were to place the icon within the menu.item.
However when i do this :
<Menu.Item key="1" icon={<HomeOutlined/>}>
<span>Home</span>
<Link to='/' />
</Menu.Item>
The icon no longer shows. I have no issues for the first approach , however when i try to tranplant the 1st approach to a submenu :
<SubMenu key="sub1" title="Settings">
<SettingFilled />
<Menu.Item key="7" onClick={this.props.logout}>
<span>Logout</span>
</Menu.Item>
</SubMenu>
It would render the icon inside the inner dropdown instead of where its supposed to be
You can try this, the icon has to be part of the title parameter in order for the icon to be shown correctly when the menu is not expanded. :-)
<SubMenu key="sub1" title={<span><UserOutlined /><span>Settings</span></span>}>
<SettingFilled />
<Menu.Item key="7" onClick={this.props.logout}>
<span>Logout</span>
</Menu.Item>
</SubMenu>
You can do this: -
<SubMenu key="sub1" title={<span><UserOutlined /><span>Settings</span></span>}>
<SettingFilled />
<Menu.Item key="7" onClick={this.props.logout}>
<span>Logout</span>
</Menu.Item>
But there will be an issue of padding as the padding of Menu.Item is given relative to the title of the Sub-Menu and the padding is given as inline-css so you will not be able to override the css and it's a bad habit to use important. Here, you are using so if you want the content aligned than you can give padding to the Link.

Xamarin.Android: When I create a button programmatically, why does it have a margin?

EDIT: I think I figured it out. It was the background in the xml that was causing the difference.
Q:
I'm trying to add buttons to my app dynamically. (I need to create 1-6 buttons)
When I try to create a button in XML (to test the appearance), it looks like this:
Buttons created in XML
Here's the xml I used to create that:
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/darker_gray"
android:text="add button"
/>
<Button
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/darker_gray"
android:text="add button"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
But when I try to create it programmatically, the buttons have a margin on the sides and they look a bit raised up.
How do I get then programmatic buttons to look the same as the XML buttons?
Is there some extra styling happening somewhere?
Dynamically created buttons (below XML buttons)
Here's the code I used to create the buttons dynamically:
var button = new Button(this);
var height = Utility.DpToPx(this, 100);
var width = ViewGroup.LayoutParams.MatchParent;
var layoutParameters = new LinearLayout.LayoutParams(width, height);
button.LayoutParameters = layoutParameters;
button.Text = "Test";
EDIT:
I think I figured it out. It's the background that I put in the xml that is causing the different effect:
android:background="#android:color/darker_gray"
My confusion was caused by the fact that I did not add a background color to the buttons that I created programatically. That is why the appearances were different.

How to enable Copy Paste for textview in Xamarin Android?

I have RecyclerView, using ViewHolder contains CardView with TextView.
For the textview, I have enabled 'textIsSelectable' property which allows you to select text and copy it.
Below is my textview:
<TextView
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtNFDescription"
android:textColor="#3f4852"
android:bufferType="spannable"
android:textIsSelectable="true" />
It works for me if I land on this page for the first time.
But if i scroll up this recycler view
OR
Navigate to another page and then land to the same page where i have this implementation. It stops working.
And OUTPUT window gives me this error when I longpress on textview after navigating or scrolling:
08-17 12:05:20.031 W/TextView(10128): TextView does not support text selection. Selection cancelled.
Any Suggestions or solutions why is this happening?

How to highlight a pressed cardView on IceCreamSandwich (Android 4.0.4)

This is my CardView layout :
<it.gmariotti.cardslib.library.view.CardView
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="#+id/list_cardId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
card:card_layout_resourceID="#layout/cardview_history"
style="#style/list_card.base"/>
Based on that layout, my CardViews layout is correctly displayed but don't get highlighted when pressed.
On IceCreamSandwich (API 15 : 4.0.4) and unlike later OS versions, if we click on a CardView, it won't be highlighted. So I tried to explicitly add a background card_selector to my CardView.
android:background="#drawable/card_selector"
I'm using the default existing drawable available in the cardslib resource (card_selector.xml) :
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_mediumAnimTime">
<item android:state_activated="true" android:drawable="#drawable/activated_background_card"/>
<item android:state_pressed="true" android:drawable="#drawable/pressed_background_card"/>
<item android:drawable="#drawable/card_background"/>
</selector>
But here is how my CardViews layout become, and as you can see, one of them is pressed but not correctly highlighted.
Is there a solution to make my CardView highlight correctly when pressed?

MVVMCross Databinding Lists with EditText

I've been playing with the monodroid/monotouch for a while now and having decided to jump from monocross to mvvmcross, I've hit a bit of a problem.
I have a domain model which contains a sub property which is a list of another domain object. Has-Many if you will. What I'm trying to do is display the aggregate root object and allow the user to fill in the details of the sub object.
public class objA
{
public List<objB> mySubObjs
}
I pretty easily got this hooked up using the MvxBindableListView. Except I couldn't bind to objA.mySubObjs, I had to bring the list up a level in the ViewModel and bind to that? Anyway, the issue I faced is that my itemtemplate for the List looked a bit like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="a)"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText xmlns:local="http://schemas.android.com/apk/res/x.x.x.x"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
local:MvxBind="{&apos;Text&apos;:{&apos;Path&apos;:&apos;Name&apos;}}" />
</RelativeLayout>
Which renders fine, but is just not useable. When I click on the editText control is brings up the softkeyboard and in doing so loses focus. I've read a couple of articles about EditText in ListView's don't work too well.
Therefore I tried building up the List view manually by binding to specific items i.e. objA.mySubObjs[0].Name, but this doesn't seem to reflect back in the ViewModel.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Question"
android:textAppearance="?android:attr/textAppearanceSmall"
local:MvxBind="{&apos;Text&apos;:{&apos;Path&apos;:&apos;Items[0].Name&apos;}}" />
I'm at a bit of a loss and didn't really want to go down the route of flattening the List within my ViewModel to accomodate the Android View.
Any help would be appreciated
Does this help - Focusable EditText inside ListView
. Except I couldn't bind to objA.mySubObjs,
on other points, feel free to ask this as a separate question - it should be possible...

Resources