Bind item object in ItemTemplate in MVVMCross - android

I am developing an MVVMCross multi platform app and I'm having the following trouble with Converters:
I have a listView in Android with the following code:
<MyProjectName.Droid.MvxCustomViews.MvxListView.MvxDroidListView
android:id="#+id/historicList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:listSelector="#00000000"
android:fadingEdge="none"
local:MvxBind="ItemsSource Historics;"
local:MvxItemTemplate="#layout/historiclistitem" />
Where, Historics is a List.
Then, I have in the layout resource:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal">
<ImageView
android:id="#+id/historicIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:layout_gravity="center"
local:MvxBind="AssetImagePath UpdateType, Converter=HistoricTypeToSource" />
<TextView
android:id="#+id/listHistoricType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Anexo"
android:textColor="#0000FF"
android:textSize="16sp"
android:layout_gravity="center"
local:MvxBind="Text UpdateType, Converter=HistoricTypeToString" />
</LinearLayout>
<TextView
android:id="#+id/listHistoricTypeDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anexo adicionado"
android:textColor="#000000"
local:MvxBind="Text ???, Converter=HistoricDetailsToString" />
The problem is, everything is working fine, but in the listHistoricTypeDetail's TextView's bind I need to pass the entire object, because, depending on each Historic.Action, I will add a text that uses Historic.AdditionalParameter, Historic.NewValue, Historic.OldValue!!!
I'm not figuring out how to pass 3 parameters depending on the value of the bind to the converter, or how to bind the entire object so my converter would be like:
MyConverter : MvxValueConverter
Is that clear? Can anyone help me?
Thanks in regards,

Given the complexity of your conversion, I think it's probably easiest to pass the entire object which you can do just by using a single period:
local:MvxBind="Text ., Converter=HistoricDetailsToString"
or - using Tibet-syntax - as:
local:MvxBind="Text HistoricDetailsToString(.)"
I think the wiki article may also help: https://github.com/MvvmCross/MvvmCross/wiki/Databinding
e.g.:
If $SourcePath$ is omitted or a single period "." is used, then the Source used is the whole of the ViewModel.
from https://github.com/MvvmCross/MvvmCross/wiki/Databinding#swiss

Related

#id is not working inside Relative Layout

As far as I know, the difference between #+id and #id is to create a resource id first time and reuse that already existed resource id in different places. For instance, If we have a Relative layout having two textViews one below another, we shall use #resourceId for the second textView which refers to the first TextView.
The problem is, after updating the android studio to 3.0, #resourceId is not working anymore.To place second textView below the first one, I need to use #+firstTextViewId instead of #firstTextViewId. More specifically I need to use,
android:layout_below="#+id/totalQty"
instead of
android:layout_below="#id/totalQty"
Here is the code
<RelativeLayout
android:id="#+id/relBottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/totalQty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abcdef"/>
<TextView
android:id="#+id/totalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/totalQty"
android:text="saasdfdsdfsdf"/>
<TextView
android:id="#+id/totalNetPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/totalPrice"
android:text="abcdsadfsafddgfdgfgdef"
/>
</RelativeLayout>
Is it an understanding issue? or a problem from any end? Can anyone please explain?
I just remove + sign at #+id from your code. Here's the updated code
<RelativeLayout android:id="#+id/relBottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/totalQty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abcdef"/>
<TextView
android:id="#+id/totalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/totalQty"
android:text="saasdfdsdfsdf"/>
<TextView
android:id="#+id/totalNetPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/totalPrice"
android:text="abcdsadfsafddgfdgfgdef"
/>
</RelativeLayout>

what is wrong in my relativelayout?

Hello everybody this is my first post here. I'm begginner in android devlopping.
I'm trying to do a listview and my list item should look likes:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageIcon"
android:layout_width="0dp"
android:layout_weight="2.5"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:src="#drawable/e3_0_1_184562_20150331100346" />
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="120dp"
android:layout_marginRight="4dp"
android:padding="5dp" >
<RelativeLayout
android:id="#+id/top1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/dscription">
<TextView
android:id="#+id/Product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/Distance"
android:text="#string/shear"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="#+id/Distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/Product"
android:layout_alignParentLeft="true"
android:text="#string/merk"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
<TextView
android:id="#+id/dscription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/thoor"
android:layout_above="#+id/bottom1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#888" />
<RelativeLayout
android:id="#+id/bottom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/name_p"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/price_p"
android:text="#string/sheor"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#888" />
<TextView
android:id="#+id/price_p"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/name_p"
android:layout_alignParentLeft="true"
android:text="#string/mir"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
I need it to looks like that
distance , product
describtion
price , seller
the distance and the product in the first line, distance in left side and product name in right side.
second line , the long desctibtion of the product.
third line (the last), I want to show the price in the left side and the seller in the right side
it doesn't work and it writes:
Exception raised during rendering: Circular dependencies cannot exist in RelativeLayout
Exception details are logged in Window > Show View > Error Log
in the error log it writes 'listitem_deal.xml Circular dependencies cannot exist in RelativeLayout'
thank you and sorry.
what is wrong in my relativelayout?
Answer : Circular dependencies cannot exist in RelativeLayout
Now, what does that mean?
Look at TextView android:id="#+id/Product and TextView android:id="#+id/Distance"
What are you doing is setting up android:layout_toRightOf="#+id/Distance" on Product and android:layout_toLeftOf="#+id/Product" on Distance.
So what Android does is look at Product first and ask, where should I position this? Right of Distance - okay so I'll look at Distance and set Product. But Distance is positioned Left of Product. So I have to look where the Product is... and so on. Do you see how it goes in circle? (there is same error with name_p and price_p)
That's what that error looks for and doesn't allow you to position it this way.
Also, to correct
The preview windows never work well and even if they do they are basically useless.
from comments - the preview feature is working just fine most of the time. This error should be raised on real device as well, not only on IDE.
To create a ListVew you need one ListView item, a structure to contain your data and one adapter to pass these data from the data source to the ListView.
Add the ListView from the layout manager(XML).
Good way to contain the data is to write your custom data class and store it in array or in others kind of structuress.
If your data class just contain one property you want to show use ArrayAdapter else you have to implement your own adapter.
You can use one Loader to query the data from the SqlLite database.
Here you can find more details:
http://www.vogella.com/tutorials/AndroidListView/article.html
http://developer.android.com/guide/topics/ui/layout/listview.html
http://developer.android.com/reference/android/widget/ListView.html

Animate Textviews within elements of a listview separately

I’ve got a layout which consists of multiple views arranged in a relative layout. This layout will be inflated within an adapter of a listview.
Now I want to animate each element of my listview separately (not the element itself, but a textview within it), for instance on an onClick event. The animation should consist of a transition of a textview, and a fading of another one.
I don’t really have an idea here. I’ve got my ArrayList of Objects which holds the data for the elements of my listview. This ArrayList is given to the adapter which fills the textviews.
I guess I need a way now to approach the textviews. But how do I do that? I fiddled around with the getView Method of the Adapter class, without any success. To get the position of the clicked element within the adapter/arraylist is no problem at all.
Any ideads/different approaches?
I tried to attach an ObjectAnimator in my Adapter, which looks like this:
ObjectAnimator animation = ObjectAnimator.ofFloat(holder.txtPlayerPoints,"x", 200);
animation.setDuration(2000);
holder.txtPlayerPoints.setTag(R.id.tag_animation_in,animation);
And in my onClick I tried to start it like so:
((ObjectAnimator ) textView.getTag(R.id.tag_animation_in)).start();
The reference to the textView is correct, but it didn't move. The Debugger also says that the "mTag" porperty of my textView is "null". Any suggestions?
Edit: Here's the layout of each element:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="#dimen/bar_upper_height"
android:paddingLeft="#dimen/bar_name_padding"
android:text="Hendrik"
android:textSize="#dimen/font_player_name"
android:id="#+id/txtNamePlayer"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/txt_default"
android:textStyle="bold"
android:textColor="#android:color/white"
android:gravity="center_vertical" />
<TextView
android:layout_width="#dimen/bar_rank_width"
android:layout_height="#dimen/bar_rank_height"
android:layout_marginLeft="#dimen/bar_upper_margin"
android:layout_marginBottom="#dimen/bar_upper_margin"
android:textSize="#dimen/font_bar_info"
android:text="1"
android:id="#+id/txtRankPlayer"
android:layout_alignLeft="#id/txtNamePlayer"
android:layout_alignBottom="#id/txtNamePlayer"
android:background="#android:color/white"
android:textStyle="bold"
android:textColor="#color/txt_default"
android:gravity="center_vertical|center_horizontal" />
<ImageView
android:layout_width="#dimen/bar_arrow_width"
android:layout_height="#dimen/bar_rank_height"
android:id="#+id/imgActivePlayer"
android:layout_toRightOf="#id/txtRankPlayer"
android:layout_marginLeft="#dimen/bar_upper_margin"
android:layout_alignBottom="#id/txtNamePlayer"
android:layout_marginBottom="#dimen/bar_upper_margin"
android:background="#drawable/active_player" />
<TextView
android:layout_width="#dimen/bar_rank_height"
android:layout_height="#dimen/bar_rank_height"
android:layout_marginRight="#dimen/bar_upper_margin"
android:layout_marginBottom="#dimen/bar_upper_margin"
android:text="12"
android:id="#+id/txtPointsPlayer"
android:layout_alignRight="#id/txtNamePlayer"
android:layout_alignBottom="#id/txtNamePlayer"
android:background="#android:color/white"
android:textStyle="bold"
android:textColor="#color/txt_default"
android:textSize="#dimen/font_bar_info"
android:gravity="center_vertical|center_horizontal" />
<TextView
android:layout_width="#dimen/bar_rank_height"
android:layout_height="#dimen/bar_rank_height"
android:layout_marginRight="#dimen/bar_upper_margin"
android:layout_marginBottom="#dimen/bar_upper_margin"
android:layout_toLeftOf="#id/txtPointsPlayer"
android:layout_alignBottom="#id/txtNamePlayer"
android:text="0"
android:id="#+id/txtCurrScorePlayer"
android:background="#color/txt_disabled"
android:textColor="#android:color/white"
android:textSize="#dimen/font_bar_info"
android:gravity="center_vertical|center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:id="#+id/aheadBehindPlayer"
android:layout_width="fill_parent"
android:layout_height="#dimen/bar_lower_height"
android:layout_below="#+id/txtNamePlayer"
android:layout_centerHorizontal="true"
android:background="#color/txt_disabled"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ahead"
android:textSize="#dimen/font_bar_info"
android:textColor="#android:color/white"
android:id="#+id/textView2"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:textSize="#dimen/font_bar_info"
android:textColor="#android:color/white"
android:id="#+id/txtPlayerAhead"
android:layout_weight="5"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:textColor="#android:color/white"
android:textSize="#dimen/font_bar_info"
android:id="#+id/txtPlayerBehind"
android:textStyle="bold"
android:gravity="right"
android:layout_weight="5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/behind"
android:textColor="#android:color/white"
android:textSize="#dimen/font_bar_info"
android:id="#+id/textView5"
android:gravity="right"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
I want to animate txtPointsPLayer and txtCurrScorePlayer.
Just attach an ObjectAnimator to each view (using setTag()) and then retrieve it later during onClick. To create an animator you can do something like:
// Animate X from 0 to 200
ObjectAnimator animation2 = ObjectAnimator.ofFloat(myview,"x", 200);
animation2.setDuration(2000);
myview.setTag(animation2)
And then during onClick you get a reference to it and start it
((ObjectAnimator ) myview.getTag()).start()
Hope it helps.
I guess this is pretty much opinion based. Even though, I'm not an android expert, I believe that whatever approach you choose you will still need to get a reference of each TextView inside the ListView, specify the OnClickListener and start the animation. So, I'd approach this in such a way that I don't keep my activity/fragment polluted with child-views-specific logic by creating a custom view that extends from the TextView class where I would define everything related to this TextViews. So, basically, the activity/fragment only needs to know how the ListView...it doesn't care about the items inside it or what the items are doing...this is from an architecture-specific perspective

how to make list views like google io 2014 app in android?

I want to create a list view layout with a image and title in it. I want a layout like listview in google io 2014 app. It should be a tiled listview with some colour till the image gets loaded, after the image is loaded it should be shown in the upper half of the listview and title should be shown below with some background colour. I am attaching the screenshot of google io app here.
Updated: If somebody can point me some template custom layout for this listview it would be helpful!
Create a custom list with all the needed controls in separate layout and inflate it using a custom adapter you can find a small example here
you could create a custom layout something like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:background="#drawable/images"
android:layout_height="match_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#862c10">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="15sp"
android:layout_marginLeft="10dip"
android:textStyle="bold"
android:text="HTML5 everywhere how and why android users use the webplatform" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="15sp"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:text="Wed 5 2001" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="15sp"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:text="Steven roberts and mark robinson " />
</LinearLayout>
</LinearLayout>
(this should not be the answer, but forgive me I could not add a comment, and actually I hope this will give him the answer).
First of all I guess you didn't get on well with using ListView and Adapter in Android. So I suggest you to read the following article first:
ListView tutorial 1
ListView tutorial 2
They will teach you how to use xml to define your custom row view. Then you will know how to use George Thomas's xml. Try how to implement the getView() method.

Android: how to make a ListView that looks similar to Preferences?

I do not want to use the framework provided Preferences, rather I would like to create a ListView that looks similar. In particular, I would like it to use the same font size and style for the TextViews.
This is not about the ListView itself, but rather the child views that appear inside the ListView. They are created by the getView method of your adapter.
To create views similar to Android, you can use the Android source code, specifically the relevant XML file layouts. For example, preference.xml looks like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="#+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="#+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/title"
android:layout_alignLeft="#android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="4" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="#+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
You will not be able to use this content directly, as some of the constants used are private to Android, and you'll have to further dig down through other xml's.
Anyhow, you should take into account that Android preferences look different on different versions of Android, and on different themes, so make sure you use the constants provided by Android, and not your own hard-coded values, to make sure your list-view items resemble the actual preferences provided by Android.
Add this attribute to the activity tag in your AndroidManifest.xml
android:theme="#android:style/Preference.PreferenceScreen"
Try this http://android-journey.blogspot.com/2010/01/for-almost-any-application-we-need-to.html

Categories

Resources