0

I'm using this library to have a HorizontalListview https://github.com/lucasr/twoway-view

Actually to try it i have this code:

shOperations = new ShortcutsOperations(getActivity());
        shOperations.open();

        List values = shOperations.getAllShortcuts();

        if (values != null) {
            ArrayAdapter<String> aItems = new ArrayAdapter<String>(getActivity(), R.layout.shortcuts_list_layout, values);
            TwoWayView lvTest = (TwoWayView)getActivity().findViewById(R.id.shortcutsListLayout);
            lvTest.setAdapter(aItems);
        }

The R.layout.shortcuts_list_layout contains a TextView and when i start the application it shows me corrected values... Now i would have inside the layout an imageview to set a drawable but i can't "access" in that layout to set the drawable.. How can i do it?

Atlas91
  • 5,238
  • 14
  • 53
  • 117

1 Answers1

0

The R.layout.shortcuts_list_layout contains a TextView and when i start the application it shows me corrected values... Now i would have inside the layout an imageview to set a drawable but i can't "access" in that layout to set the drawable.. How can i do it?

you need a custom Adapter. You can subclass BaseAdapter and implement the abstract methods, or better a subclass of CursorAdapter, since you are working with the database

I'm using this library to have a HorizontalListview https://github.com/lucasr/twoway-view

you can achieve the same with the new RecyclerView, part of the android sdk. If you decide to use this widget you need a different type of Adapter. You have to extend RecyclerView.Adapter<T>

Blackbelt
  • 148,780
  • 26
  • 271
  • 285
  • And then from the BaseAdapter have i to access to values in the database? Have you please a similar example? – Atlas91 Jun 28 '15 at 18:21
  • your values are in `List values`? – Blackbelt Jun 28 '15 at 18:32
  • look [here](http://stackoverflow.com/questions/16338281/custom-adapter-getview-method-is-not-called) for an example (The question). I saw that your `getAllShortcuts()` returns a `List`. How do you which image belongs to which string – Blackbelt Jun 28 '15 at 18:35
  • Shortly, from a listview in which i have all applications installed when you click over one of them you save its package name. That string is the package name and from that i will able to retrieve the icon of the application – Atlas91 Jun 28 '15 at 19:53