listview simple example not working

21 views
Skip to first unread message

Johnny TwoShoes

unread,
Dec 28, 2015, 9:32:56 AM12/28/15
to RoboBinding
Hi,

I've got a simple listview that displays two strings twin1 and twin2. Twin is defined as:
public class Twin {
    public Twin(String twin1, String twin2) {
        this.twin1 = twin1;
        this.twin2 = twin2;
    }
    public String getTwin1() {
        return twin1;
    }
    public void setTwin1(String twin1) {
        this.twin1 = twin1;
    }
    public String getTwin2() {
        return twin2;
    }
    public void setTwin2(String twin2) {
        this.twin2 = twin2;
    }
    private String twin1;
    private String twin2;
}

and ViewModel:
@PresentationModel
public class MainActivityViewModel {

    private static final String SELECTED_SOURCE_INDEX = "selectedSourceIndex";

    private List<Twin> twins;

    public MainActivityViewModel() {
        twins=Lists.newArrayList();
        twins.add(new Twin("John","James"));
        twins.add(new Twin("Jack","Joseph"));
        twins.add(new Twin("Jane","Jo"));
        twins.add(new Twin("James","Joe"));
    }
    public int getSelectedSourceIndex() {
        return selectedSourceIndex;
    }
    public void setSelectedSourceIndex(int selectedSourceIndex) {
        this.selectedSourceIndex = selectedSourceIndex;
        Log.d("mypp", "setSelectedSourceIndex CALLED: "+selectedSourceIndex);
    }
    private int selectedSourceIndex;
    @ItemPresentationModel(value= TwinItemPresentationModel.class)
    public List<Twin> getDynamicTwins()
    {
        Log.d("mypp", "getDynamicStrings CALLED");
        return twins;//SampleStrings.getSample();
    }
    public void onItemSelected(ItemClickEvent event) {
        Log.d("mypp", "onItemSelected CALLED: "+event.getPosition());
        //setDynamicStrings(getDynamicStrings().get(event.getPosition()));
    }
    public void setDynamicTwins(List<Twin> twins) {
        this.twins = twins;
    }
}

TwinItemPresentationModel:
public class TwinItemPresentationModel implements ItemPresentationModel<Twin> {
    public Twin getTwin() {return twin;}
    public void setTwin(Twin twin) { this.twin = twin;}
    private Twin twin;
    @Override
    public void updateData(Twin twin, ItemContext itemContext) {  this.twin = twin; }
}
row_item_layout:
<?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="horizontal"
    android:background="@drawable/my_list_selector_background">

    <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        bind:text="${twin1}"
        android:id="@+id/edtComment"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/txtDesc"
        bind:text="{twin2}"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

</LinearLayout>
and the main xml:
<?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="match_parent"
    android:orientation="vertical"
    xmlns:bind="http://robobinding.org/android" >
    <ListView
        bind:itemLayout="@layout/row_item_layout"
        bind:source="{twins}"
        bind:selectedItemPosition="${selectedSourceIndex}"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" />
</RelativeLayout>

but, when I run it, I get error:
source: No such dataSet property 'info.androidhive.tabsswipe.ViewModel.MainActivityViewModel.twins'

any ideas? Also, bind:selectedItemPosition="${selectedSourceIndex}" doesn't work? How do I know what is the value of index?

regards

cheng

unread,
Dec 28, 2015, 5:30:09 PM12/28/15
to RoboBinding
Hi Johnny,

If you check the error message carefully, you will know it is complaining it could not find twins property, which is info.androidhive.tabsswipe.
ViewModel.MainActivityViewModel.getTwins(). Where your one is info.androidhive.tabsswipe.ViewModel.MainActivityViewModel.getDynamicTwins(). To use RoboBinding, you will have to have a good self-learning and self-issue shooting capability, as it is open source. Otherwise, i will suggest you to use libraries from Android official.

Cheers,
Cheng

在 2015年12月29日星期二 UTC+11上午1:32:56,Johnny TwoShoes写道:

Johnny TwoShoes

unread,
Jan 1, 2016, 11:30:38 AM1/1/16
to RoboBinding
ok thanks. And regarding why bind:selectedItemPosition="${selectedSourceIndex}" doesn't work? Any ideas?

wei cheng

unread,
Jan 1, 2016, 5:02:53 PM1/1/16
to robob...@googlegroups.com

Is it working in Gallery sample?

--
You received this message because you are subscribed to the Google Groups "RoboBinding" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robobinding...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Johnny TwoShoes

unread,
Jan 2, 2016, 1:58:37 PM1/2/16
to RoboBinding
Hi Cheng,

Sorry. I will check and get back to you.

kind regards

Johnny TwoShoes

unread,
Jan 3, 2016, 1:42:32 PM1/3/16
to RoboBinding
Hi Cheng, 

bind:onItemClick is working fine, on the listview,so , I didn't bother with bind:selectedItemPosition="${selectedSourceIndex}", though, I will go back to it soon, and check out your example.


kind regards
Reply all
Reply to author
Forward
0 new messages