Forum Discussion

David91's avatar
David91
Frequent Contributor
2 years ago

Android ListView wSelected return false

Hi, 

 

i have a problem with ListView on Android via Emulator. I need check, which item was selected and return his position in list. 

 

 

 

 var listView = Aliases.Device.Process_androidclient_Dev.Layout_NO_ID.Layout_action_bar_root.Layout_content.Layout_vmc_main_content_area.ListView("vmc_screen30_list");

listView.SelectItem(3)
var value = listView.wSelected(3) // return false

 

 

 

Would anyone know how to do this on android?

 

Thank you πŸ™‚

  • Kitt's avatar
    Kitt
    Regular Contributor

    I have no experience with this personally, but there is some TestComplete documentation for Android ListView Support [here]. Do you get any specific errors when running your code?

    • David91's avatar
      David91
      Frequent Contributor

      I have read the documentation, of course.

       

      I don't know how to simply find out the row in the listview that is selected. 😞

       

      Do you have any tip?

       

      Thank you

      • Kitt's avatar
        Kitt
        Regular Contributor

        I assume you could use the examples provided [here] to check the ListView item's state.

  • Kitt's avatar
    Kitt
    Regular Contributor

    If you are asking for help on a community forum I cannot just assume you have read all of the documentation, as most people don't, nor can I assume anything further than "I clicked object, it returns false - what do I do?"  The item isn't selected if it's returning false, which is why I suggested you use the TC example for finding all states and focus properties of the items in your ListView - which also links to additional principles of addressing list view items. I also do not know what type of application you are testing which could have an effect if you are using custom items in your list - but now I can assume you have already read that documentation [here] too.

     

    Have you tried using listView.TouchItem() instead of listView.SelectItem()? Or verified the item's property actually changes after it is selected? Are you using the correct property and index? What even is SelectItem(3)? Why are we all here? Why does my wife say she's not hungry and then eat my food?

     

    Asking for help is a two way street: have some patience, understand that community members are blindly attempting to diagnose an issue that isn't our own, and that we need as much context and information as possible in order to provide clear and concise answers. Happy testing!

    • David91's avatar
      David91
      Frequent Contributor

      Ok, no problem. the problem in my opinion is that there is no classic item in the sheet but one row is one Layout see  .. this is one line in listView

      Mobile.Device("emulator-5554").Process("mobileclient.androidclient.Dev").Layout("NO_ID").Layout("action_bar_root").Layout("content").Layout("vmc_main_content_area").ListView("vmc_screen100_list").Layout("NO_ID")

       

      need to somehow find out which row (Layout) is marked in the sheet. I've been struggling with this for a week but I can't figure it out... πŸ˜•

       

      Thank you

      • Kitt's avatar
        Kitt
        Regular Contributor

        Could you try a Record Script test to see how TestComplete is doing it, then post the code output here, along with a screenshot of the item in question from the ObjectBrowser? 

         

        Also, please copy the code from here, run it, and post the results here if you can.

         

        function CheckState()
        {
          // Select an Android device
          Mobile.SetCurrent("MyDevice");
        
          // Obtain an application
          var app = Mobile.Device("emulator-5554").Process("mobileclient.androidclient.Dev");
        
          // Obtain a listView
          var listViewObj = app.RootLayout("").ListView("vmc_screen100_list"); 
            // or app.RootLayout("").Layout("vmc_main_content_area").ListView("vmc_screen100_list") 
         
          for (i=0; i < listViewObj.wItemCount; i++)
          {
            // Check the item’s state
            if (listViewObj.wSelected(i))
            {
              Log.Message(listViewObj.wItem(i) + " item is checked");
            }
            else
            {
              Log.Message(listViewObj.wItem(i) + " is not checked");
            }
          }
        
          // Obtain the index of item with focus
          var focus = listViewObj.wFocus;
          if (focus == -1)
          {
            Log.Message("There are no focused items.");
          }
          else
          {
            Log.Message("The index of the focused item is " + focus);
          }
        }

         

  • Kitt's avatar
    Kitt
    Regular Contributor

    I think it would be most helpful if you create a new Record Script test to see how TestComplete is doing it, then post the code output here, along with a screenshot of the item in question from the ObjectBrowser.