0

I want to have EditText within the MvxListView that has ItemLongClick binding working normally in it (using template). The development framework that I used is MvvmCross within Xamarin.Android (written in C#).

I have tried the normal approach, and the EditText seems taking all of the focusable within the MvxListView item. It means, the ItemLongClick only works within the EditText part of the item. It is important to know when I disable the focusable of EditText (android:focusable="false"), the ItemLongClick works within all part of the item (in sacrifice of EditText not working). The last thing that I have tried is set android:descendantFocusability="blocksDescendants" on my root element (based on this answer) of my item layout and it acts the same as disabling the EditText focusable.

Below is the code I wrote.

MvxListView in .axml

...
<Mvx.MvxListView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    local:MvxItemTemplate="@layout/table_shipment_item_layout"
    android:divider="#BCBCBC"
    android:dividerHeight="1dp"
    android:descendantFocusability="afterDescendants"
    android:focusable="false"
    local:MvxBind="ItemsSource ScannedItems; ItemLongClick RemoveItemCommand;" />
...

table_shipment_item_layout.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="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/custom_clickable_item">
    ...
    <EditText
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="16.0dp"
        android:text="5"
        android:padding="8.0dp"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="#000000"
        android:textColorHint="#D3D3D3"
        android:background="@drawable/custom_textbox"
        android:inputType="number|numberDecimal"
        android:digits="0123456789."
        android:layout_gravity="right|center_vertical"
        local:MvxBind="Text Quantity;" />
</LinearLayout>

As you can see, I am using the EditText, so users are able to edit the quantity of every scanned item. Is there any workaround for this? I am also open to another method aside from EditText within MvxListView if there is any. Thanks in advance.

Community
  • 1
  • 1
Darren Christopher
  • 3,893
  • 4
  • 20
  • 37

1 Answers1

0

You are using android:descendantFocusability="blocksDescendants" is in your Mvx.MvxListView thats not working you need to add it to your root Layout of row row xml.

one more think you have declare android:focusable="false" in Mvx.MvxListView thats is also not working you need to add in your child xml inner layouts like in your case EditText .

And as per experience EditText in ListView not working properly .if you want to take input from each row separately.

You can take TextView in place of EditText and open and input Dialog with EditText and get your input value and set into your TextView and your DataList.

OR

you can create Custom ListView by using ScrollView and Lienarelayout and EditText ,in this way do not need to open and input Dialog.

Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43
  • Yes, I have tried all of those `descendantFocusability` and none of those works. They are there because I have not removed it after trying many times. Is there any other method you could suggest to overcome this issue based on your experience? – Darren Christopher Mar 07 '17 at 07:40
  • Thank you for your suggestion. Is there any link or tutorial for using input `Dialog` with `EditText`? By using `ScrollView`, will it still use `local:MvxItemTemplate` and `ItemsSource` binding? If so, should the item template also stealing focusable of the parent? – Darren Christopher Mar 07 '17 at 07:59
  • you need to create one dialog while click on EditText . please follow this link for Dialog http://techblogon.com/alert-dialog-with-edittext-in-android-example-with-source-code/ – Chetan Joshi Mar 07 '17 at 09:20