如何夸大里面的GridView适配器getView()另一个布局在android系统? [英] How to inflate another layout inside getView() of gridview adapter in android?

查看:240
本文介绍了如何夸大里面的GridView适配器getView()另一个布局在android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想创建每周日历视图和每个网格项目(每天)里面有可能有几个这样我一直在使用网格视图中创建每周日历视图activities.Out,但我想补充的活动,如果有任何通过动态特定日期检查分贝。像一样的图像。
下面是我getView()code ..

I want to create weekly calendar view and inside each grid item (each day) there are may be several activities.Out of this I have created weekly calendar view using grid view but I want to add activities if there are any for particular date by dynamically checking db. Like same as in image. Below is my getView() code..

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.calendar_week_gridcell, parent, false);
    }

    txtRowTitle = (TextView) row.findViewById(R.id.txtDayTitle);

    LinearLayout root = (LinearLayout) row.findViewById(R.id.linear_root);

    String dayTitle = list.get(position);
    txtRowTitle.setText(dayTitle);
    if (position == currentWeekDay - 1)
        root.setBackgroundResource(R.drawable.calheader);
    if (!activityMap.isEmpty() && activityMap.containsKey(activityDateList.get(position))) {
        TextView item = new TextView(mContext);
        item.setText(activityMap.get(activityDateList.get(position)));
        item.setBackgroundColor(Color.GREEN);
        root.addView(item);
    }

    return row;
}

}

在这里,我暂时想动态添加文本的看法,但我想在这里夸大我的自定义布局activity_item并将其添加到网格单元格。

Here I am temporarily trying to add text view dynamically but I want to inflate here my custom activity_item layout and add it to grid cell.

推荐答案

你的意思是你想在现在正在采取忙的空间区域添加多行?你想,因为它需要其采取尽可能多的空间,或者它应该是滚动?

do you mean that you wish to add multiple rows in the area that is now being taken by the "Busy" space ? do you want it to take as much space as it needs, or should it be scrollable?

反正,看来你是在正确的方向。您使用的LinearLayout保持忙区域,对不对?所以只需使用一个for循环,并把他们的数据,你希望显示。

anyway, it seems you are in the right direction. you used a linearLayout to hold the "busy" area, right? so just use a for-loop and put their the data you wish to show.

当然,因为在GridView回收项目,则需要每次到达getView时间清空的LinearLayout,但它应该仍然可以工作。

of course, because the gridView recycles items, you would need to empty the linearLayout every time you reach the getView, but it should still work.

如果您希望使用layoutInflater在for循环,这也是可能的:

if you wish to use the layoutInflater in the for-loop, that's also possible:

 subRow = inflater.inflate(R.layout.sub_row, linearLayout, true);

这篇关于如何夸大里面的GridView适配器getView()另一个布局在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆