How to Bind Android TextView to Click event with MvvmCross - android

Is it possible to Bind Android TextView to Click event with MvvmCross?
Or as alternative make a button which looks like TextView?

It is turned out that TextView can be bound same way as Button
local:MvxBind="Click DoCommand"

You can bind a text view like this.
<TextView android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Click DoThisCommand" />
height and width you can manage according to your convinience.
Hope this will help you.

As the OP may be interested in methods to achieve click binding from code-behind as opposed to xml I have provided the following for guidance:
using MvvmCross.Platforms.Android.Binding;
var set = this.CreateBindingSet<theActivity,theViewModel>();
imageView1.For(x=> x.BindClick()).To(vm=>vm.imageViewClickCmd);
set.Apply()
The MvvmCross.Platforms.Android.Binding namespace provides the BindClick() extension method. Similar methods can be found for alternative events at the following links https://www.mvvmcross.com/documentation/fundamentals/data-binding#built-in-bindings
Alternatively you can use
imageView1.For("Click").To(vm=>vm.imageViewClickCmd);

Related

How to display placeholder Chips within ChipGroup in xml?

I have a layout with a ChipGroup whose chips will be populated programmatically, but I want to visualise how chips will look like within the layout, is there a way to show fake chips like for example using the tools namespace?
Not really the solution, you asked for, but it gets the job done.
If someone's got a better solution, let me know.
I solved it with a hardcoded chip, which has the visibility set to GONE and inside the tools namespace visibility set to VISIBLE.
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
tools:text="Leichter Genuss" />

Extended Android Floating Button

I developed Android Application and I want to use extended floating button like floating button on Path Application in my layout. I hope someone can give me example about the code how to make this things. Thank You.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hellooooo"
app:icon = "#drawable/pass_resource_here"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
</com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton>
Here's a detailed tutorial on how to create a good extended floating button with animations https://www.learn2crack.com/2015/10/android-floating-action-button-animations.html
Try using this library and modify it to your liking by using the sam ple project in the library
https://github.com/oguzbilgener/CircularFloatingActionMenu

Android detect and clickable web address in textview

I am working on textview, I want to do that if there is any web link in textview so it will detect that and also clickable. How can I achieve that?
There are two main ways - xml which does most work for you (see #Massimo answer) and code which is very flexible, it allows you to make some text clickable and intercept link clicks (see LinkMovementMethod)
Set the autoLink and linksClickable attributes in your xml's TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:linksClickable="true"
android:autoLink="web"/>

How to set default text in TextView to see it in the layout preview while binding?

So I would like to see my layout preview with the fields filled with something like default placeholders but if I use bindings the settext attribute is already used and the fields are showing empty since there is no info from the models yet.
<TextView
android:id="#+id/tv_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
**android:text="#{showBlueportSpotViewModel.name}"**
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"/>
I tried this:
android:text="#{showBlueportSpotViewModel.name ?? #string/blueport_placeholder_name}"
but I still see the view empty.
Do you guys any workaround? I guess once a workaround is found, it can be used to ImageView and src for example and etc..
Thank you!
You can use the tools attribute to define properties that will appear in the layout preview but will not appear when you run the app.
Add the following to your root view:
xmlns:tools="http://schemas.android.com/tools"
Then use the tools attribute to define text that will only appear in the layout preview:
tools:text="placeholder text"
The tools attribute is very useful when mocking up views in the editor. All of the tools attributes are stripped when the app is packaged. More information here: http://tools.android.com/tech-docs/tools-attributes
I found a workaround
I added
xmlns:bind="http://schemas.android.com/apk/res/android"
to the layout
and just having duplicated declarations in the view like:
android:text="#string/blueport_placeholder_name"
bind:text="#{showBlueportSpotViewModel.name}"
or
android:src="#{showBlueportSpotViewModel.blueportImageDrawable}"
bind:src="#drawable/android_menu_header"
I don't really know if this has secondary wrong consequences so I won't accept this answer until somebody can comment and say if it is okay.. Thanks!

android changing text view (is this code ok?)

Can some one help me, I have heard alot of things and I dont know what to believe. I am making an app that is a counter. In my xml layout i have a TextView acting as a counter and the text is set by a string in strings.xml and i am controlling what the text view says from my java file. here is some code snip its. all I want to know is this ok?, it works fine but I want to know is it a bad or good way.
"counter" equals a variable.
"display" is referencing the ID of the textview"
what i am using to control the text view.
display.setText(String.valueOf(counter));
here is my text view in my xml layout
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDisplay"
android:gravity="center"
android:text="#string/counter"
android:textSize="20dp" />
here is the string in strings.xml
<string name="counter">0</string>
It's fine, that's how you change text dynamically.
Yes, All things are right and good. Yo should have to give the String Value as like that.
If there is a Small Value of TextView then you can directly give as android:text="abcd"
And If you want to give any reference of that then your code is also correct and works as well.
For the Best use of coading your should have to try as like you have done rightnow. as Because it helps you a lot if there are number of TextView and you want to manage or change the Value of it quickly.
Enjoy. :)
Thanks.

Categories

Resources