Janpan
Janpan

Reputation: 2274

Gridview with listview inside android

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.

Upvotes: 1

Views: 3206

Answers (1)

kyogs
kyogs

Reputation: 6836

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.

Upvotes: 1

Related Questions