DevHossamHassan / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

clickLongInList does not work on a gridView #653

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. attach a long click listener on a gridview object
2. call solo.clickLongInList(0); (assuming cell number 0) 
3.

What is the expected output?
the onItemLongCLickListener to be called on the gridview

What do you see instead?
nothing happens

What version of the product are you using?
Robotium Solo 5.2.1

On what operating system?
Android 4.4

Please provide any additional information below.
here is my work code
    gridView.setAdapter(pictureAdapter);
        gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                editing = !editing;
                pictureAdapter.setEditing(editing);
                return true;
            }
        });
and this is my test code
  public void test7ClickOnGallery_longClickOnCellShouldShowX() {
        solo.sleep(1000); // wait for grid items to load
        solo.clickLongInList(0);
        GridView gridView = solo.getView(GridView.class, 0);
        if(gridView.getAdapter().getCount()>0) {
            View firstCell = gridView.getChildAt(0);
            PictureGridAdapter pictureGridAdapter = (PictureGridAdapter) gridView.getAdapter();
            Assertions.assertThat(pictureGridAdapter.isEditing()).isTrue();
            PictureGridViewHolder vh = (PictureGridViewHolder) firstCell.getTag();
            Assertions.assertThat(vh.isEditing()).isTrue();
            assertThat(vh.getImageButton()).isVisible();

        }
    }

the above version of the test does not call the longItemClickListener

this version of the test does - and so it passes
public void test7ClickOnGallery_longClickOnCellShouldShowX() {
        solo.sleep(1000);
        GridView gridView = solo.getView(GridView.class, 0);
        if(gridView.getAdapter().getCount()>0) {
            View firstCell = gridView.getChildAt(0);
            solo.clickLongOnView(firstCell);
            PictureGridAdapter pictureGridAdapter = (PictureGridAdapter) gridView.getAdapter();
            Assertions.assertThat(pictureGridAdapter.isEditing()).isTrue();
            PictureGridViewHolder vh = (PictureGridViewHolder) firstCell.getTag();
            Assertions.assertThat(vh.isEditing()).isTrue();
            assertThat(vh.getImageButton()).isVisible();

        }
    }

Original issue reported on code.google.com by lena...@gmail.com on 25 Jan 2015 at 3:04

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. Would it be possible for you to share an app that 
exhibits this issue?

Original comment by renasr...@gmail.com on 27 Jan 2015 at 1:48

GoogleCodeExporter commented 9 years ago
After further investigations it seems that it just doesnt find the right 
gridview, if i have a ViewPager fragment with several fragments that contain a 
listview/gridview in them, and the viewpager pages are not 100% in width (less 
than 100%). My mistake was that I assumed that solo clicks on the currently 
visible gridview, and it seems that it doesnt. It clicks on the first list/grid 
that it finds, which is not visible, but is in a viewpager which has a 
partially visible page - to reproduce that, I'd have to give you my current, 
app, which I cannot do

Original comment by lena...@gmail.com on 28 Jan 2015 at 9:27

GoogleCodeExporter commented 9 years ago
You can specify which View to click with clickLongInList(int line, int index)

Original comment by renasr...@gmail.com on 6 Feb 2015 at 3:47