1

I have a view in my app where I have to display multiple listviews alongside each other, each containing data for a different user. So what I have done so far is I have a gridview with columns, and within each column I populate the gridview cell with a listview. This works fine, however, it displays the same listview twice, instead of displaying different listviews for each column. The strange thing is that if I replace the list view with a normal label, it displays the data from different users.

Main Activity where I set the gridview adapter:

gridview.setNumColumns(10);
                gridview.setHorizontalSpacing(205);
                gridview.setStretchMode(0);
                gridview.setAdapter(new Adapter_Labels_GridView_Calendar_dayview(mContext, Session_CurrentSession.current_CALENDAR));

This is the adapter for the gridview... just the getview section. (You will see that is where I set the adapter for the listviews that displays the same listview and not different ones)

 public View getView(int position,View convertView, ViewGroup parent)
 {

  ListView list;

  if (convertView == null)
  {  
       // if it's not recycled, initialize some attributes  
       list = new ListView(mContext);
       list.setLayoutParams(new GridView.LayoutParams(150, 500));
       list.setPadding(2,2,2,2);
   }  
  else
  {  
       list = (ListView) convertView;  
  }  


  list.setAdapter(new Adapter_ListView_GridView_Calendar(mContext, dagtyeVanhaarkappers.get(position), gebookdeurUser.get(position), tekening.get(position)));
  list.setCacheColorHint(0);

  list.setId(position);

  list.setOnTouchListener(new View.OnTouchListener()
        {

            public boolean onTouch(View v, MotionEvent event)
            {   
                // Disallow the touch request for parent scroll on touch of child view
                v.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });

  return list;
 }  

}

Thanks in Advance

EDIT:

Here is the gridview on touch event in the main activity:

  gridview.setOnTouchListener(new View.OnTouchListener()
     {

            public boolean onTouch(View v, MotionEvent event)
            {
               if(isDayView && created)
               {
                   int numchilds = gridview.getChildCount();
                   for(int i = 0; i < numchilds; i++)
                   {
                       gridview.getChildAt(i).getParent().requestDisallowInterceptTouchEvent(false);

                   }
               }
                return false;
            }
        });

EDIT: getview of Adapter_ListView_GridView_Calendar

        public View getView(int position, View convertView, ViewGroup parent)
    {

            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.row_bookingslist, parent , false);

            ImageView booking_image = (ImageView) rowView.findViewById(R.id.booking_image);
    TextView textBookingTime = (TextView) rowView.findViewById(R.id.booking_time);
    TextView textBookingUser = (TextView) rowView.findViewById(R.id.booking_byuser);

            booking_image.setImageDrawable(drawables.get(position));
            textBookingTime.setText(daytimes.get(position));
            textBookingUser.setText(bookedbyuser.get(position));


    return rowView;
}

ANSWER FINALLY:

I've found the problem... I thought the problem was with the adapter because of my weird view (Listview inside gridview)... However, I was not making new instances of the data when reading them into an arraylist using a for loop, so the string had the same reference in memory. Thus, when modyfying either one, I was actually modyfying the same instance of that object. Damn, can't beleive I did not see such a simple little thing. Thank You for all the help.

11
  • Post the comment of your Adapter_ListView_GridView_Calendar getView() class. You say the list is repeated that means the adapter in the listview is setting the same data somewhere. You ened to check that properly! Commented Jan 22, 2013 at 7:12
  • Do you want the entire class ? Commented Jan 22, 2013 at 7:18
  • I want the code of getView() of Adapter_ListView_GridView_Calendar if you can provide? Commented Jan 22, 2013 at 7:57
  • sure thing, I'll edit it in the original post. Commented Jan 22, 2013 at 8:05
  • Ok, that does not help anything. Could you try one thing? Put a debug point in the Contructor of Adapter_ListView_GridView_Calendar and check if you are getting the same data there? Commented Jan 22, 2013 at 8:07

1 Answer 1

1
final View rowView = inflater.inflate(R.layout.list_mobile, parent, false);
    ListView listView = (ListView) rowView.findViewById(R.id.raw_mylist);

    listView.setAdapter(adapter);

            // PARENT
    mListView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            Log.v("PARENT", "PARENT TOUCH");
            rowView.findViewById(R.id.raw_mylist).getParent()
                    .requestDisallowInterceptTouchEvent(false);
            return false;
        }
    });

            //your grid view as child
    listView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            Log.v("CHILD", "CHILD TOUCH");
            // Disallow the touch request for parent scroll on touch of
            // child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

in getview method of your main adapter.

Sign up to request clarification or add additional context in comments.

4 Comments

I do not have a listviewm in the xml layout, I create them in code dynamically. I already do what you proposed above.
but u didnt wrote gridview touch in ur getview method.
I did it in the main activity, I will edit in the main post to show.
It does exactly the same. Just note that the touch and scrolling works fine, the problem is that its displaying the same results twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.