0

This a sample calendar use gridview , now i want add new thing in calendar "day" , so i think i can use the listview layout in the month of day , now i have probleam is how can i use the listview in the gridvie adapter !

and this is my calendar adapter part code

public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        TextView dayView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.calendar_item, null);

        }
        dayView = (TextView)v.findViewById(R.id.date);
        listitem=(ListView)v.findViewById(R.id.listView1);
        // disable empty days from the beginning
        if(days[position].equals("")) {
            dayView.setClickable(false);
            dayView.setFocusable(false);
        }
        else {
            // mark current day as focused
            if(month.get(Calendar.YEAR)== selectedDate.get(Calendar.YEAR) && month.get(Calendar.MONTH)== selectedDate.get(Calendar.MONTH) && days[position].equals(""+selectedDate.get(Calendar.DAY_OF_MONTH))) {
                v.setBackgroundResource(R.drawable.item_background_focused);
            }
            else {
                v.setBackgroundResource(R.drawable.list_item_background);
            }
        }
        dayView.setText(days[position]);
        for(int t=0;t<date.size();t++){
        if(days[position]== date.get(t).get(2)){
            listitem.setAdapter(new ArrayAdapter<String>(mContext,
                    android.R.layout.simple_list_item_1));

        }
        }
        // create date string for comparison
        String date = days[position];

        if(date.length()==1) {
            date = "0"+date;
        }
        String monthStr = ""+(month.get(Calendar.MONTH)+1);
        if(monthStr.length()==1) {
            monthStr = "0"+monthStr;
        }

        // show icon if date is not empty and it exists in the items array
       // ImageView iw = (ImageView)v.findViewById(R.id.date_icon);
      /*  if(date.length()>0 && items!=null && items.contains(date)) {          
            iw.setVisibility(View.VISIBLE);
        }
        else {
            iw.setVisibility(View.INVISIBLE);
        }*/
        return v;
    }
Nermeen
  • 15,883
  • 5
  • 59
  • 72
  • I don't think you need to really show all that code. Show us less code from `getView` and more code from the xml on `GridView`. – Andy Dec 21 '12 at 07:07
  • http://stackoverflow.com/questions/9295794/listview-inside-gridview-not-scrolling這是我probleam的解決方案谷歌不建議這樣做 – user1902932 Dec 21 '12 at 09:02

1 Answers1

0

Well, It shouldn't be that hard, I suppose.

Instead of regular gridview child you need to inflate an xml with listview in it. Like this, I think.

            LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            if (showListView)
                v = vi.inflate(R.layout.listview_item, null);
            else
                v = vi.inflate(R.layout.calendar_item, null);

than it goes with something like this

if(showListView){
        ListView listview = (ListView) v.findViewById(R.id.listview);
        listview.setAdapter(new SuperListviewAdapter());}
        else{
            //show regular item
        } 
return v;

I haven't tried this, but you might encounter some problems with touch events (like gridview will consume listview touch events?).

Sver
  • 3,349
  • 6
  • 32
  • 53
  • the listview get in girdview i finish , but i have another probleam is ,i can not contact my listview scroll , it maybe when i toutch the listitem is stop for gridview thank you – user1902932 Dec 21 '12 at 08:53