I am Creating MvvmCross PCL using Visual Studio 2013 and targeting frameworks are
WP8 and higher
.Net Framwork 4.5 and higher
Silverlight 5
Xamarin Android
Xamarin iOS
In one of my MvxViewModel,I have one public property of List in data from some service is get stored.In android , I have populated a MvxListView with this
List .
Now upon clicking one of the listitem I want to call new viewModel which also populate another List.And corresponding MvxListView will have a ItemTemplate as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/KittensView.Droid"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text Name" />
<RatingBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Text Rating" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next" />
</LinearLayout>
In this axml layout,I want to show one listItem at a time and upon clicking on above button,a next listItem Should replace existing listItem until all the data in a corresponding List is gets displayed on UI.
How can I achieve this?PLEASE help me......
Thanks in advance for any helpful suggestions.
You can create properties for: a list of your objects (DataItem), an instance of your object and index
private int _index = 0;
private List<DataItem> _dataitems;
private DataItem _dataItem;
public DataItem DataItem {
get { return _dataItem; }
set
{
DataItem = value;
RaiseOnProperty(()=>DataItem);
}
public IMvxCommand ShowNextItemCommand
{
get
{
return new MvxCommand(()=> {
_index++;
DataItem = _dataitems.ElementAt[_index]
});
}
}
In your AXML, you can do this :
<?xml ... />
<LinearLayout ...
<TextView ...
local:MvxBind="Text Name1" />
<TextView ...
local:MvxBind="Text Name2" />
<Button ...
android:text="Next"
local:MvxBind="Click ShowNextItemCommand" />
</LinearLayout>
I think it works.
Related
I'm trying to add a button on top of Map Activity, in the layout.
I just want to show a button over the map layout, but I tried different layouts, Constraint, Relative... and nothing works. I also tried to put the map fragment in XML before and after the button inside a relative layout, and yet it did nothing, it shows only the map.
I resized the map and even removed the map layout, and still the map shows in full screen.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="#+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="270dp"
android:layout_height="336dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context="com.parse.starter.RidersActivity" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
You don't need to say the orientation for constraintLayout. Just make your fragment sizes android:layout_width="match_parent" and
android:layout_height="match_parent" , add button and constraint it to your fragment:
You don't need to say the orientation for constraintLayout. Just make your fragment sizes android:layout_width="match_parent" and
android:layout_height="match_parent" , add button and constraint it to your fragment:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
It looks like this :
Just Make your Fragment height and weight attribute match_parent
Try below code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="160dp"
android:layout_marginBottom="652dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
I hope its work for you
i finally found the problem, i accidentally created 2 similar activities and i was editing the wrong activity, that's why there were no errors. Thanks everybody who tried to help.
Having issue while binding MvvmCross.Binding.Droid.Views.MvxSpinner with data.
Spinner dropdown showing perfectly fine with string but spinner title showing object reference only.
Spinner
<MvvmCross.Binding.Droid.Views.MvxSpinner
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxDropDownItemTemplate="#layout/spinner_item"
android:layout_marginLeft="5dp"
android:dropDownWidth="257dp"
android:dropDownSelector="#drawable/list_item_selector"
local:MvxBind="ItemsSource Cities" />
Templete
<?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="wrap_content"
android:layout_height="wrap_content"
android:background="#fafafa"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="32dp"
android:textSize="15sp"
android:textColor="#de000000"
android:lineSpacingExtra="5sp"
android:text="Shortness of breath"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_marginLeft="24dp"
local:MvxBind="Text Name; Typeface StringToFont('Effra_Rg')" />
</MvvmCross.Binding.Droid.Views.MvxLinearLayout>
Please go through the link for snapshot
You are not providing a MvxDropDownItemTemplate:
local:MvxDropDownItemTemplate="#layout/template"
nor a MvxItemTemplate:
local:MvxItemTemplate="#layout/template"
The difference between these two are, that the Drop Down Item Template is what is show when the spinner is expanded. While the Item Template will be the first item shown when it is collapsed. You probably need to provide them both if you do not wish to use the default templates which just call ToString() on the ViewModel bound to the item.
I have read multiple posts for solutions on how to display a WebView over an ImageView. Here is what I tried last and it still doesn't work:
mPhotoWebView.setWebViewClient(new WebViewClient());
mPhotoWebView.setBackgroundColor(0x00000000);
xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp" >
<com.example.android.views.MyImageView
android:id="#+id/photoImageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<WebView
android:id="#+id/photoWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarStyle="insideOverlay"
android:scrollbars="none" />
html style:
body
{
background:transparent;
background-color: rgba(10,10,10,0.5);
}
This code needs to run on 4.2.2. What I am trying to accomplish, is the webview has animation code done in html5 and the imageView is a background image that the animations need to show over.
Any ideas?
I must have missed this combination before. My final solution, that works is:
Do not set background color to webView in the code.
body
{
background:transparent;
overflow: hidden;
background-color: rgba(10,10,10,0.5);
}
xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp" >
<com.accuweather.android.views.MyImageView
android:id="#+id/photoImageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<WebView
android:id="#+id/photoWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:layerType="software"
android:scrollbarStyle="insideOverlay"
android:scrollbars="none" />
Key here is the software layerType. I am using a fragment of which one activity handles many, so I couldn't do this in the manifest. Therefore I did so in the xml.
I want to play video in listview from online server as like VINE app. And plays only one video at a time.But videoview cann't show in listview. I can view all others like text, links. But VideoView cann't show in listview row. show all without videoview. when try without listview it works fine and play video from online
my listview adapter code snippet like this:
mViewHolder.mVideoView.setVisibility(View.VISIBLE);
MediaController mComtroller = new MediaController(mContext);
mViewHolder.mVideoView.setMediaController(mComtroller);
mViewHolder.mVideoView.setVideoURI(Uri.parse("myLink"));
mViewHolder.mVideoView.start();
mViewHolder.mVideoView.requestFocus();
layout row of listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="80"
android:weightSum="10"
android:orientation="horizontal"
android:background="#drawable/background" >
<VideoView
android:id="#+id/vv_surface_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_weight="5" />
<ImageView
android:id="#+id/iv_videoThumbnail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:background="#drawable/background" />
</LinearLayout>
<TextView
android:id="#+id/tv_VideoName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_weight="10" />
</LinearLayout>
I have an MvxListView that I'm showing some recipe cards in. When the user clicks a card they should be taken to a detail screen. The problem I'm running into is that when there is a CheckBox (bound or unbound) in the cell, the entire cell ignores the click event.
My MvxListView is created with:
<MvxListView
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Recipes; ItemClick ShowRecipeDetailCommand"
local:MvxItemTemplate="#layout/use_recipe_list_item"
android:divider="#android:color/transparent"
android:dividerHeight="10dp" />
The List item is created with:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical"
android:background="#color/use_detail_recipe_background"
android:padding="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"
android:id="#+id/tvTitle"
android:textSize="24sp"
local:MvxBind="Text Title"
android:layout_weight="1"
android:layout_toLeftOf="#+id/cbFavorite"
android:textColor="#color/use_detail_recipe_title_text" />
<!-- <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cbFavorite"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:checked="false"
android:layout_weight="0" />-->
<View
android:id="#+id/vDivider1"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#000000"
android:layout_below="#+id/tvTitle" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Content"
android:id="#+id/tvContent"
android:singleLine="false"
android:layout_below="#+id/vDivider1"
local:MvxBind="Text Content"
android:textColor="#color/use_detail_recipe_content_text"
android:maxLines="4"/>
</RelativeLayout>
If the checkbox isn't commented out, this works. How can I work around this? Would it be possible to add a command to the click on my base RelativeLayout in the item?
Thanks for the tip Stuart. This is indeed not a MvvmCross issue but rather a general Android issue.
The solution was to add the following to each clickable item:
android:focusable="false"
android:focusableInTouchMode="false"
This comment got me on the right track https://stackoverflow.com/a/15859831/83301.