TextView Clickable in MVVMCross - android

I have floating button in the FundamentalView.axml
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="22dp"
android:paddingRight="22dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true">
<ImageButton
android:id="#+id/addButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:src="#drawable/ic_add_white_24dp" />
</FrameLayout>
In the FundamentalView.cs, I have click event which triggers a fragment from the bottom of the view with having options (adding a new person and new calculations).
var addButton = view.FindViewById<ImageButton>(Resource.Id.addButton);
addButton.Click += OnAddButtonClick;
void OnAddButtonClick(object sender, System.EventArgs e)
{
var dialog = new CardDialogView();
dialog.Show(((MainView)Activity).SupportFragmentManager, "CardDialogView");
}
CardDialogView.axml
<?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"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_computer"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Calculation"
local:MvxBind="Click NewCalculationCommand"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_head"
android:drawablePadding="28dp"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Person" />
</LinearLayout>
My question is how to make TextView clickable and know which textview clicked in mvvmcross?
CardDialogView.cs
public class CardDialogView : MvxDialogFragment<CardDialogViewModel>
{
public override Dialog OnCreateDialog(Bundle savedState)
{
.....
return dialog;
}
}
CardDialogViewModel.cs
public class CardDialogViewModel : MvxViewModel
{
public ICommand NewCalculationCommand
{
get
{
// it does not come here!
return new MvxCommand(() => ShowViewModel<NewItemViewModel>(new { date = DateTime.Now }));
}
}
}

You can bind textview click just like as button click:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_computer"
android:textColor="#color/primary_text"
android:textSize="16sp"
local:MvxBind="Click NewCalculationCommand"
android:text="New Calculation" />
For the second textview bind it to another command. This way when the corresponding command is invoked you will know which textview triggered it.

Related

How to remove empty white space in the custom dialog android?

How to remove the empty space in the dialog. My code-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_2x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_2x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_1_point_25_x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_1_point_25_x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.25X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_normal_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_normal_75x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_75x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.75X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/quality_dialog_5x_radio_btn_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/quality_dialog_point_5x_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.5X"
android:textSize="16sp"
android:textColor="#003FBC"
android:padding="5dp"/>
</LinearLayout>
</LinearLayout>
My Java Code
View alertLayout = View.inflate(this, R.layout.quality_dialog_layout, null);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setView(alertLayout);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();
Suggestion 1:
In order to customize the AlertDialog theme you have to create a new theme for it, which is a bit complicated and quite hard as you have also to create proper images etc.
Regarding this option you can check this topic here
Suggestion 2:
Include the button in the xml:
<Button android:text="OK"
style="?android:attr/borderlessButtonStyle" />
Suggestion 3:
Use the AlertDialog options and don't change the theme, this will add proper spacing in all options and follow the android theming so it will not look strange, but will not remove the spacing you mentioned:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setSingleChoiceItems(R.array.your_array_options, null/* no item preselected*/,
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// handle the item selection here
}
}
);
alert.setCancelable(true);
qualityAlertDialog = alert.create();
qualityAlertDialog.show();
and the your_array_options will be in a file res/values/array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="your_array_options">
<item>2X</item>
<item>1.5X</item>
<item>1.25X</item>
...
</string-array>
</resources>
Suggestion 4:
In order to have full customized theme then do not use AlertDialog at all but DialogFragment:
public class MyDialogFragment extends DialogFragment {
// ...
// Empty constructor required for DialogFragment
public MyDialogFragment() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.quality_dialog_layout, container);
TextView quality2XView = alertLayout.findViewById(R.id.quality_dialog_2x_view_id);
TextView quality1_5View = alertLayout.findViewById(R.id.quality_dialog_1_5x_view_id);
TextView quality1_Point25View = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_view_id);
TextView qualityNormalView = alertLayout.findViewById(R.id.quality_dialog_normal_view_id);
quality_point75View = alertLayout.findViewById(R.id.quality_dialog_point_75x_view_id);
quality_point5View = alertLayout.findViewById(R.id.quality_dialog_point_5x_view_id);
quality2XRadioBtn = alertLayout.findViewById(R.id.quality_dialog_2x_radio_btn_view_id);
quality1_5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_5x_radio_btn_view_id);
quality1_Point25RadioBtn = alertLayout.findViewById(R.id.quality_dialog_1_point_25_x_radio_btn_view_id);
qualityNormalRadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_radio_btn_view_id);
quality_point75RadioBtn = alertLayout.findViewById(R.id.quality_dialog_normal_75x_radio_btn_view_id);
quality_point5RadioBtn = alertLayout.findViewById(R.id.quality_dialog_5x_radio_btn_view_id);
// This will also require to add extra buttons in the xml!
// getDialog().setTitle("If you want to change the title");
return view;
}
}

relaunch application without changing

I found some code to press home button from code
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
and This one :
moveTaskToBack(true);
I have a activity that is in single task
And a alertDialog with a button then you click on the button one of those code run and go to home
so when you go to app again the alert dismissed before
I want to relaunch the app without dismissing alertDialog
What can i do?
thanks
AlertDialog default button will dissmis dialog .
you should create custom dialog with custom view
public class CustomDialog extends AlertDialog(){
TextView mTitleView,mDescriptionView;
Button mYesButton,mNoButton,mCancelButton;
boolean isYesButtonVisible = true;
boolean isNoButtonVisible = true;
boolean isCancelButtonVisible = true;
public CustomDialog(Context context){
super(context);
}
public void setYesButtonVisible(boolean isVisible){
isYesButtonVisible = isVisible
}
public void setNoButtonVisible(boolean isVisible){
isNoButtonVisible = isVisible
}
public void setCancelButtonVisible(boolean isVisible){
isCancelButtonVisible = isVisible
}
#override
public void show(){
super.show();
setContentView(R.layout.dialog_custom);
mTitleView = findViewById(R.id.text_title);
mDescriptionView = findViewById(R.id.text_description);
mYesButton = findViewById(R.id.btn_yes);
mNoButton = findViewById(R.id.btn_no);
mCancelButton = findViewById(R.id.btn_cancel);
isYesButtonVisible ? mYesButton.setVisibility(View.VISIBLE) : mYesButton.setVisibility(View.GONE);
isNoButtonVisible ? mNoButton.setVisibility(View.VISIBLE) : mNoButton.setVisibility(View.GONE);
isCancelButtonVisible ? mCancelButton.setVisibility(View.VISIBLE) : mCancleButton.setVisibility(View.GONE);
}
//must be called after dialog is showing else you will get NullPointerException
public void setOnYesClickListener(View.OnClickListener listener){
mYesButton.setonClickListener(listener);
}
public void setOnNoClickListener(View.OnClickListener listener){
mNoButton.setonClickListener(listener);
}
public void setOnCancelClickListener(View.OnClickListener listener){
mCancelButton.setonClickListener(listener);
}
}
and layout dialog_custom can be designed by yourself too but this is my layout file for custom dialog
<?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">
<TextView
android:id="#+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/btn_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/yes"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/btn_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/no"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/cancel"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
While creating AlertDialog with Builder you can set setCancelable(false);.

MvvmCross Databinding Not working as expected

I am currently experiencing a weird issue with MvvmCross on android. I want to data bind a a view to a ViewModel. My setup is as follows
public class ForumTopicItemsViewModel : MvxViewModel
{
ObservableCollection<ForumReplyListModel> _forumComments;
ForumTopicDetailsModel _topic;
long _forumId;
long _topicId;
bool _busy;
int _page;
public ForumTopicItemsViewModel()
{
_topic = new ForumTopicDetailsModel()
{
DateCreated = DateTime.Now.AddDays(-1),
Discussion = "Just the fact that I dont care about what is displayed here",
ForumId = ForumId,
TopicId = TopicId,
Topic = "Another Heading, Just for the sake of it"
};
_forumComments = new ObservableCollection<ForumReplyListModel>
{
new ForumReplyListModel()
{
CreatedBy = "Peter Edike",
DateCreated = DateTime.Now.AddDays(-1),
Reply = "Just a reply to show how far I have come"
}
};
}
public int Page
{
get { return _page; }
set { SetProperty(ref _page, value); }
}
private static bool IsHostReachable()
{
var nReachability = Mvx.Resolve<IMvxReachability>();
return nReachability.IsHostReachable(AppConfiguration.RequestUrl);
}
public ObservableCollection<ForumReplyListModel> Comments
{
get { return _forumComments; }
set { SetProperty(ref _forumComments, value); }
}
public ForumTopicDetailsModel Topic
{
get { return _topic; }
set { SetProperty(ref _topic, value); }
}
public string Heading => this.Topic.Topic;
public string Description => this.Topic.Discussion;
public string DateCreatedString => this.Topic.DateCreatedString;
public bool Busy
{
get { return _busy; }
set { SetProperty(ref _busy, value); }
}
public long ForumId
{
get { return _forumId; }
set {SetProperty(ref _forumId, value); }
}
public long TopicId
{
get { return _topicId; }
set { SetProperty(ref _topicId, value); }
}
public void Init(long TopicId, long ForumId)
{
this.TopicId = TopicId;
this.ForumId = ForumId;
}
}
and I have the Android XML View Like So
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:MvxBind="Refreshing Busy; RefreshCommand LoadReplyCommand">
<MvxRecyclerView
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:MvxItemTemplate="#layout/listitem_commentlist"
app:MvxBind="ItemsSource Comments;" />
</MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout>
<View
android:layout_width="match_parent"
android:layout_height="4px"
android:background="#color/grey_soft" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="#dimen/spacing_medium"
app:cardElevation="#dimen/spacing_xsmall"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/spacing_medium"
android:layout_marginLeft="#dimen/spacing_large"
android:layout_marginRight="#dimen/spacing_large"
android:layout_marginTop="#dimen/spacing_large"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:textColor="#color/upload_photo_button_color"
app:MvxBind="Text Heading" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
android:text="#string/lorem_ipsum"
app:MvxBind="Text Description"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/grey_dark" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#color/grey_soft" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
app:MvxBind="Text DateCreatedString"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/upload_photo_button_color"
android:textStyle="italic" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Problem:
The contents of the MvxRecyclerView are never displayed even though i made sure that the collection had items in the constructor.
Every other binding works as expected. If I however comment out everything except the MvxRecyclerView, it becomes visible.
Please I think I did something wrong.
Can someone point me in the right direction?
Thank You.
None of your LinearLayout's seem to have an orientation set. I think the default one is set to Horizontal meaning your layout flows from left to right and go outside of the visible area of your screen.
Also another problem is that your layout is awfully nested, meaning it will probably have a significant amount of overdraw and extra measurement passes when it is going to be drawn on the screen. You can un-nest it by using a single RelativeLayout instead of the 4 nested layers of LinearLayout.
Something like this might work:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout
android:layout_alignParentTop="true"
android:layout_above="#+id/divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:MvxBind="Refreshing Busy; RefreshCommand LoadReplyCommand">
<MvxRecyclerView
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:MvxItemTemplate="#layout/listitem_commentlist"
app:MvxBind="ItemsSource Comments" />
</MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout>
<View
android:id="#+id/divider"
android:layout_above="#+id/heading_card"
android:layout_width="match_parent"
android:layout_height="4px"
android:background="#color/grey_soft" />
<android.support.v7.widget.CardView
android:id="#+id/heading_card"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="#dimen/spacing_medium"
app:cardElevation="#dimen/spacing_xsmall"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/spacing_medium"
android:layout_marginLeft="#dimen/spacing_large"
android:layout_marginRight="#dimen/spacing_large"
android:layout_marginTop="#dimen/spacing_large"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:textColor="#color/upload_photo_button_color"
app:MvxBind="Text Heading" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
android:text="#string/lorem_ipsum"
app:MvxBind="Text Description"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/grey_dark" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#color/grey_soft" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
app:MvxBind="Text DateCreatedString"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/upload_photo_button_color"
android:textStyle="italic" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>

ViewModel does not get called in MVVMCross

In the FundamentalView.cs, I have click event which triggers a fragment from the bottom of the view with having options (adding a new person and new calculations).
var addButton = view.FindViewById<ImageButton>(Resource.Id.addButton);
addButton.Click += OnAddButtonClick;
void OnAddButtonClick(object sender, System.EventArgs e)
{
var dialog = new CardDialogView();
dialog.Show(((MainView)Activity).SupportFragmentManager, "CardDialogView");
}
CardDialogView.axml
<?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-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_computer"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Calculation"
local:MvxBind="Click NewCalculationCommand"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_head"
android:drawablePadding="28dp"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Person" />
</LinearLayout>
CardDialogView.cs
public class CardDialogView : MvxDialogFragment<CardDialogViewModel>
{
public override Dialog OnCreateDialog(Bundle savedState)
{
......
return dialog ;
}
}
The following corresponding ViewModel does not get called? I wonder what I am missing?
CardDialogViewModel.cs
public class CardDialogViewModel : MvxViewModel
{
public ICommand NewCalculationCommand
{
get
{
return new MvxCommand(() => ShowViewModel<NewItemViewModel>(new { date = DateTime.Now }));
}
}
}
You are missing this from the CardDialogView.axml layout file xmlns:local="http://schemas.android.com/apk/res-auto"
CardDialogView.axml should be this:
<?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-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_computer"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Calculation"
local:MvxBind="Click NewCalculationCommand"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dash_add_head"
android:drawablePadding="28dp"
android:textColor="#color/primary_text"
android:textSize="16sp"
android:text="New Person" />
</LinearLayout>
Think you need to set the viewmodel on the CardDialogView like so:
void OnAddButtonClick(object sender, System.EventArgs e)
{
var dialog = new CardDialogView();
dialog.ViewModel = new CardDialogViewModel();
dialog.Show(SupportFragmentManager, "CardDialogView");
}

getCheckedRadioButtonId just gives me nullpoint exception

Im having some issues, i have two Groups of Radiobuttons in my XML which has handling in an activity. It just crashes with nullpoint exception on line 48:
int languangeId = languageGroup.getCheckedRadioButtonId();
I have set a "default" checked button in the XML to one of the buttons in the buttongroup,
So why doesnt it get an valid value?:(
public class FirstTimeSelectMenu extends Activity{
private RadioGroup languageGroup;
private RadioGroup storageGroup;
private Button okButton;
private String getStorage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_time_run);
languageGroup = (RadioGroup)this.findViewById(R.id.languageGroup);
storageGroup = (RadioGroup)this.findViewById(R.id.storageGroup);
okButton = (Button)findViewById(R.id.okBtn);
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int languangeId = languageGroup.getCheckedRadioButtonId();
int storageId = storageGroup.getCheckedRadioButtonId();
RadioButton languageb = (RadioButton)findViewById(languangeId);
RadioButton storageb = (RadioButton)findViewById(storageId);
if(languageb.equals("Norwegian")){
//Need to fix this!
}
if(languageb.equals("English")){
//Need to fix this!
}
if(storageb.equals("SD Card")){
String sdStoragePath = Environment.getExternalStorageDirectory().toString() + "/PictureTalk/";
FileInteraction fi = new FileInteraction();
fi.firstTimeFillPath(getResources(), "PictureTalk/Food", sdStoragePath +"PictureTalk/Food");
fi.firstTimeFillPath(getResources(), "PrivatePictures", Environment.getExternalStorageDirectory().toString() +"PrivatePictures");
Intent intent = new Intent(getApplicationContext(),MainMenuActivity.class);
intent.putExtra("dataStorePath",sdStoragePath);
startActivity(intent);
}
}
});
}}
My XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/languagetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="236dp"
android:text="Choose language" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/languagetext"
android:layout_alignRight="#+id/languagetext"
android:layout_below="#+id/languageGroup">
<RadioButton
android:id="#+id/norwegianRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Norwegian" />
<RadioButton
android:id="#+id/englishRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="English" />
</RadioGroup>
<TextView
android:id="#+id/internal_sd"
android:layout_width="464dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="236dp"
android:text="Do you want to store the data to:" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="#+id/storageGroup">
<RadioButton
android:id="#+id/sdcardRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:checked="true"
android:text="SD card" />
<RadioButton
android:id="#+id/internalRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Internal storage" />
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:id="#+id/okBtn"
android:layout_gravity="bottom" />
To start off with, what element is assigned the id "#+id/languageGroup" since it doesn't appear to be declared in your XML

Categories

Resources