Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24414] Android - Fails to cast Ti ListView to native ListView

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop
Labelsandroid, engSchedule, hyperloop, listview, searchview
ReporterJames O'Leary
AssigneeJan Vennemann
Created2017-02-16T18:56:40.000+0000
Updated2019-09-24T15:47:15.000+0000

Description

I'm trying to access native ListView methods. I need to cast a Ti ListView to a native Android ListView to access the native methods. I'm using the following link as a reference: [http://docs.appcelerator.com/platform/latest/#!/guide/Android_Hyperloop_Programming_Guide] You can use the snippet of code:
var tiListView = Ti.UI.createListView({});
var ListViewClass = require('android.widget.ListView');
var nativeListView = new ListViewClass(tiListView);
Running the above code will give you the following error: {noformat} [ERROR] : HyperloopProxy: (main) [5496,10667] Unable to find matching constructor for class: android.widget.ListView, args: [ti.modules.titanium.ui.widget.listview.TiListView$ListViewWrapper{d8c5545 V.E...CL. ......I. 0,0-0,0 #1e}] {noformat} You can also can get the Hyperloop-Examples project from appcelerator's github page and replace the button.js controller in the project with the button.js file I attached. [https://github.com/appcelerator/hyperloop-examples] The reason why I want to access native methods on the ListView is to get the count of visible ListViewRows in the ListView when searching through the ListView with a SearchView. It seems that I can only get the count of all(visible and hidden) ListViewRows in the ListView. If you have a solution for this without using Hyperloop, I'd love to hear that as well. Thank you in advanced.

Attachments

FileDateSize
button.js2017-02-16T18:51:33.000+00005508

Comments

  1. Sharif AbuDarda 2017-02-16

    Hello, Whats your SDK version and Hyperloop version that you are testing on?
  2. James O'Leary 2017-02-16

    @sdarda SDK 6.0.1.GA Hyperloop 2.0.0
  3. Sharif AbuDarda 2017-02-17

    I have teste dthe issue with SDK 6.0.1.GA with the sample code provided and the hyperloop example project. This is a valid bug.
  4. Igor Kalashnikov 2017-05-08

    Hi, I've found same issue I think rootcause is that in Android ListView is wrapped by 'ListViewWrapper' [TiListView.java#L331](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/TiListView.java#L331)
       //initializing listView and adapter
       ListViewWrapper wrapper = new ListViewWrapper(activity);
       wrapper.setFocusable(false);
       wrapper.setFocusableInTouchMode(false);
       listView = new ListViewScrollEvent(activity);
       listView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
       wrapper.addView(listView); // <==================== HERE
       adapter = new TiBaseAdapter(activity);
       
  5. Josh Lambert 2018-02-17

    I'm seeing this same bug on the latest TiSDK+Hyperloop. Any updates on patching it?
       [ERROR] HyperloopProxy: (main) [172,492] Unable to find matching constructor for class: android.widget.ListView, args: [ti.modules.titanium.ui.widget.listview.TiListView$ListViewWrapper{882ebb0 V.ED..CL. ......ID 0,0-0,0 #1}]
       
  6. James O'Leary 2018-02-20

    @Josh, I think @Ihor is on track with finding a solution. I haven't tried this code or Hyperloop in a while but I think you must use the ListViewWrapper in order to cast the Ti ListView to a native Android ListView. Anyway I'm commenting to say that I've moved on. I've decided Hyperlooop is more of a headache than it's worth. My team is in the transition to write more Native apps while still keeping Appcelerator in our back pocket for select apps. Good luck!
  7. Igor Kalashnikov 2018-11-11

           if (OS_ANDROID) {
               const ListView = require('android.widget.ListView');
               const View = require('android.view.View');
               const ViewGroup = require('android.view.ViewGroup');
       
               (function (tiList) {
                   const listWrapper = new View(tiList);
                   const nativeListView = ViewGroup.cast(listWrapper).getChildAt(1);
                   const list = ListView.cast(nativeListView); // Got ListView here 
                   list.smoothScrollToPositionFromTop((itemIndex + 1 /* 1st section*/), 0, 100);
               })($.eventsFeed);
           } 
       
    I'm getting to Android's native ListView using this code (hope it will helps)
  8. Michael Gangolf 2018-11-11

JSON Source