简体   繁体   中英

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

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. 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. Is there any way to change background when API less then 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);
} 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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