Editable List view item

155 views
Skip to first unread message

Thiago Lacerda

unread,
Aug 10, 2012, 4:41:36 PM8/10/12
to android...@googlegroups.com
Hi Andy,

Now i need to make a list of contacts and i want to make it editable from the listview itself.
The problem is that the values which i put in the list items are not reflecting in the bindables...
Is there any way to make it?
Thanks in advance.

Best regards

Thiago Lacerda



Andy Tsui

unread,
Aug 10, 2012, 10:04:03 PM8/10/12
to android...@googlegroups.com
Not too understand: 
list items are not reflecting in the bindables 

Can you elaborate more and/or show your vms?

Thiago Lacerda Siqueira

unread,
Aug 14, 2012, 10:01:03 AM8/14/12
to android...@googlegroups.com
Hi Andy,

Excuse about  the delay in the response.
Here is the case:

I have an object that represents a person with an array of contacts:

public class BindablePerson extends Bindable<Person> {
    public final StringObservable name = new StringObservable();
    public final StringObservable socialSecurityNumber = new StringObservable();
    public final StringObservable mainActivity = new StringObservable();
    public final StringObservable experience = new StringObservable();
    
    public final ArrayListObservable<BindableContactInformation> contacts = new ArrayListObservable<BindableContactInformation>(BindableContactInformation.class);

}


public class BindableContactInformation extends Bindable<ContactInformation> {

    public final StringObservable description = new StringObservable();
    public final StringObservable remarks = new StringObservable();
    public final Observable<BindablePerson> person = new Observable<BindablePerson>(BindablePerson.class);
    
    public BindableContactInformation(BindablePerson person) {
    this.person.set(person);
    }
    
}

Then i created a listview with person contacts: 

<?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:background="?android:attr/activatedBackgroundIndicator"
    android:baselineAligned="false"
    android:focusable="false"
    android:gravity="left|center"
    android:orientation="vertical"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingTop="5dp" >

    <ListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:binding="http://www.gueei.com/android-binding/"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/contacts_listview"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:choiceMode="singleChoice"
        binding:itemSource="person.contacts"
        binding:itemTemplate="@layout/personedit_contact_items" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right" >

        <Button
            android:id="@+id/button1"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="@string/add"
            binding:onClick="addContact" />
    </LinearLayout>

</LinearLayout>


And its items:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:binding="http://www.gueei.com/android-binding/"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/activatedBackgroundIndicator"
        android:baselineAligned="false"
        android:focusable="false"
        android:gravity="left|center"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingLeft="5dp"
        android:paddingTop="5dp" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <EditText
                android:id="@+id/contactedit_description"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="text"
                binding:clickable="editMode"
                binding:focusable="editMode"
                binding:text="description" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/remarks" />

            <EditText
                android:id="@+id/contactedit_remarks"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:gravity="top"
                android:inputType="textMultiLine"
                android:lines="2"
                binding:clickable="editMode"
                binding:focusable="editMode"
                binding:text="remarks" >
            </EditText>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right" >

            <Button
                android:id="@+id/contactedit_btn_edit"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="@string/edit"
                binding:onClick="editRecord"
                binding:visibility="NOT(editMode)" />

            <Button
                android:id="@+id/contactedit_btn_save"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="@string/save"
                binding:onClick="saveRecord"
                binding:visibility="editMode" />

            <Button
                android:id="@+id/contactedit_btn_cancel"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="@string/cancel"
                binding:onClick="cancel"
                binding:visibility="editMode" />

            <Button
                android:id="@+id/contactedit_btn_remove"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="@string/delete"
                binding:onClick="deleteRecord"
                binding:visibility="NOT(editMode)" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>


The VM looks like:

public class PersonEditViewModel extends BaseViewModel {

public final BindablePerson person;

public final Command addContact = new Command() {
@Override
public void Invoke(View view, Object... args) {
BindableContactInformation contact = new BindableContactInformation(person);
person.contacts.add(contact);
}
};
.
.
.
}

The problem is that when i make editions in a contact, the description and remarks fields informed in contact row will not binds the alterations to the correspondent item in contacts array of person, its fields remain as null.

I hope I have been more clear now.
Thanks in advance.

Best regards,

Thiago Lacerda


2012/8/10 Andy Tsui <guee...@gmail.com>

Andy Tsui

unread,
Aug 14, 2012, 11:00:33 AM8/14/12
to android...@googlegroups.com
I think you better check the log cat output, it seems perfectly valid to me and it should be working.. 

Thiago Lacerda Siqueira

unread,
Aug 14, 2012, 3:01:54 PM8/14/12
to android...@googlegroups.com
Log cat tells nothing about it.
When i change the values in contact information fields, the view load the values, but when i modify the view, the fields in the list item remains the same...
In debug i can see the observables being notified, but the item instance in list is not modified in any moment.
I'm a little bit lost, because as you said, the markup and code seems to be valid...

Best Regards,

Thiago Lacerda


2012/8/14 Andy Tsui <guee...@gmail.com>

Thiago Lacerda Siqueira

unread,
Aug 14, 2012, 4:06:56 PM8/14/12
to android...@googlegroups.com
Now i have sure that the set method of the Observable is never called when changing the list item in view, i thinking about the observables not are being registered to be notified when item list is added...
What you think?

Best Regards,


Thiago Lacerda


2012/8/14 Thiago Lacerda Siqueira <thia...@gmail.com>

Andy Tsui

unread,
Aug 14, 2012, 9:21:35 PM8/14/12
to android...@googlegroups.com
i thinking about the observables not are being registered 
That's what I doubt too, and if anything wrong with the markup, log cat should show something. 

Thiago Lacerda Siqueira

unread,
Aug 14, 2012, 11:25:51 PM8/14/12
to android...@googlegroups.com
The markup is ok then...
The log cat have no error...
Can you try to reproduce this issue? And post me the results?

Best regards,


Thiago Lacerda


2012/8/14 Andy Tsui <guee...@gmail.com>:

Andy Tsui

unread,
Aug 14, 2012, 11:58:30 PM8/14/12
to android...@googlegroups.com
possible.. what you are doing is:

1. have a list of stuff
2. have a button to add
3. after adding, and editing the added item, nothing is changed

is that so?

Andy

Thiago Lacerda Siqueira

unread,
Aug 15, 2012, 8:44:49 AM8/15/12
to android...@googlegroups.com
Exactly.
Thanks in advance for your help.
I need to deliver the prototype in this friday and after all i have
tried this trouble is the one that remains yet.

Best regards,

Thiago Lacerda


2012/8/15 Andy Tsui <guee...@gmail.com>:

Andy Tsui

unread,
Aug 15, 2012, 9:37:45 AM8/15/12
to android...@googlegroups.com
BTW, I suggest you replace Tab View with Bindable Layouts later on.. Tab View is very hard to maintain and not flexible enough. also I feel that Google will fade TabView away.. 

Thiago Lacerda Siqueira

unread,
Aug 15, 2012, 11:40:46 AM8/15/12
to android...@googlegroups.com
Hi Andy!

Im using bindable layouts indeed.
My prototype is entirely based in New Markup Demo...
Im using bindable layouts, bindable action bar with list navigation,
metadata files, etc
As i said to you before, i think your implementation of binding
layouts is far better than the fragments one.
Congratulations for the great framework.

Andy Tsui

unread,
Aug 15, 2012, 12:09:30 PM8/15/12
to android...@googlegroups.com
Thanks.. but I can't take all the credits, bindable layouts are suggested by other member :)

Thiago Lacerda Siqueira

unread,
Aug 15, 2012, 12:17:27 PM8/15/12
to android...@googlegroups.com
Well, that is the secret behind open projects... =]


2012/8/15 Andy Tsui <guee...@gmail.com>:

Thiago Lacerda Siqueira

unread,
Aug 16, 2012, 9:13:25 AM8/16/12
to android...@googlegroups.com
Hi Andy!
Some success in reproducing the error?
--
Um Abraço,


Thiago Lacerda

Andy Tsui

unread,
Aug 16, 2012, 10:28:10 PM8/16/12
to android...@googlegroups.com
Hi, 

first I have to apologize, the "BindableLayout" email is not mean for you, I have sent to wrong person :P

Next, that's a point I also forgot, the "EditText"'s text attribute is not a String, but a CharSequence, which if you put a String there, it will not serve two way binding.. To make it work, simply put CharSequenceObservable instead of StringObservable will be fine, I attached the test project I have to you. Enjoy. 

Andy
AddAndEditListItem.zip

Thiago Lacerda Siqueira

unread,
Aug 17, 2012, 9:23:59 AM8/17/12
to android...@googlegroups.com
Hi Andy!

You are a life saver!
The strings now are binding like a charm.
You gave me the fish now i want to know to catch it! Can you tell how
the FW does this relation between atribute type and observable is
done? In my model i have some observables of objects and in these
cases the binding is made in one way only.
Thanks a lot for your help.

Best Regards,

Thiago Lacerda


2012/8/16 Andy Tsui <guee...@gmail.com>:

Thiago Lacerda Siqueira

unread,
Aug 17, 2012, 10:41:47 AM8/17/12
to android...@googlegroups.com
Hi Andy!

Forget it! I found in calculator example the converter concepts and it
is exactly what i needed.
Once more, thanks a lot for your help and congratulations for the
great framework.

Best Regards,

Thiago Lacerda


2012/8/17 Thiago Lacerda Siqueira <thia...@gmail.com>:

Andy Tsui

unread,
Aug 17, 2012, 11:12:28 AM8/17/12
to android...@googlegroups.com
Basically there are 2 binding types to attributes: one-way and two-way. one way means you can assign value to view attr but not vice versa, example to this will be Text, you can put any Observable<Object> to it, and it will translate to Object.toString(). In this case, of course it cannot go back. 

For two-ways, both attr and observable must be exactly the same type, reason for this is obvious. 

In some cases view attributes are readonly, for example clickedItem for ListViews, but still those I consider them to be two-way. 

Yeah, converter is really powerful pattern and I personally found many interesting situations beyond my intended design. For example, you can add behavior to a View without subclassing it,  I once made a "SeekBar" and make it "snap" to integer values, pure accomplished by using converter. 

Andy
Reply all
Reply to author
Forward
0 new messages