简体   繁体   English

setview的textview不起作用

[英]setbackground of textview not working

I am using ExtendedCalendarView to draw year and month days here is the link of ExtendedCalendarView enter link description here 我正在使用ExtendedCalendarView绘制年月日,这是ExtendedCalendarView的链接,请在此处输入链接说明

Now I get Calendar programmatically and then selected day which I want, should change their background image Just like 现在我以编程方式获取日历,然后选择所需的日期,应更改其背景图像,就像

ExtendedCalendarView extendedCalendarView = (ExtendedCalendarView) findViewById(R.id.calendar);
GridView calendar = (GridView) extendedCalendarView.findViewById(999);
calendar.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapter, View view, int pos,long id) {
        TextView dayTV = (TextView)view.findViewById(R.id.textView1);
        dayTV.setBackgroundResource(R.drawable.ic_launcher);
    }   
}

Now I face issue, the issue is to set background, when API level less than 17 its does not seems to work, the cell selected which I want to select but its background does not change. 现在我面临一个问题,问题是设置背景,当API级别小于17时,它似乎不起作用,我想要选择的所选单元格却没有改变,但其背景不变。 Its working with XML android:background="@drawable/ic_launcher" and there is no issue with that but I have constraints which prevent me that day could not selected, that's why I could not use XML. 它可以与XML android:background="@drawable/ic_launcher"一起使用,并且没有问题,但是我有限制,无法选择那天,这就是为什么我不能使用XML的原因。 Is there any way to change background when API less then 17 当API小于17时,是否有任何方法可以更改背景

Thanks 谢谢

// your code looks good if textview is inside GridView;
This code is for textview outside:

ExtendedCalendarView extendedCalendarView = (ExtendedCalendarView) findViewById(R.id.calendar);
GridView calendar = (GridView) extendedCalendarView.findViewById(999);
TextView dayTV = (TextView) findViewById(R.id.textView1);

calendar.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapter, View view, int pos,long id) {
dayTV.setBackgroundResource(R.drawable.ic_launcher);
} 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM