Hoping someone can help me here. I have a layout which contains listview, each item in the list view contains individual text fields to represent the days of the week --> SMTWTFS
What I am trying to do is change the colour of the text items if they are set within the database. This nearly works but I have noticed the first row in the list view changes the colour for all items when the are set in other list rows.
My text items are declared like this
textSUN = (TextView) v.findViewById(R.id.textSUN);
textMON = (TextView) v.findViewById(R.id.textMON);
textTUE = (TextView) v.findViewById(R.id.textTUE);
textWED = (TextView) v.findViewById(R.id.textWED);
textTHU = (TextView) v.findViewById(R.id.textTHU);
textFRI = (TextView) v.findViewById(R.id.textFRI);
textSAT = (TextView) v.findViewById(R.id.textSAT);
I then query my db and set the adapter
db = new DatabaseHandler(getActivity());
mCursor=db.getReadableDatabase().rawQuery("SELECT rowid _id,* "+
"FROM table", null);
adapter = new SimpleCursorAdapter(getActivity(),
R.layout.list_row, mCursor,
new String[] {DatabaseHandler.KEY_SUNDAY, DatabaseHandler.KEY_MONDAY,DatabaseHandler.KEY_TUESDAY,DatabaseHandler.KEY_WEDNESDAY, DatabaseHandler.KEY_THURSDAY, DatabaseHandler.KEY_FRIDAY,
DatabaseHandler.KEY_SATURDAY,},
new int[] {R.id.textSUN,R.id.textMON, R.id.textTUE, R.id.textWED, R.id.textTHU, R.id.textFRI, R.id.textSAT});
Finally I try to set the color in the view binder if the value returned is 1 from the db
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Cursor cursor, int
columnIndex) {
final int sun_column = cursor.getColumnIndex("sun");
final int mon_column = cursor.getColumnIndex("mon");
final int tue_column = cursor.getColumnIndex("tue");
final int wed_column = cursor.getColumnIndex("wed");
final int thu_column = cursor.getColumnIndex("thu");
final int fri_column = cursor.getColumnIndex("fri");
final int sat_column = cursor.getColumnIndex("sat");
}
if (columnIndex == sun_column) {
int sun = cursor.getInt(cursor.getColumnIndexOrThrow("sun"));
if(sun == 1){
((TextView) view).setTextColor(Color.parseColor("#FFFFFF"));
}
return true;
}
if (columnIndex == mon_column) {
int mon = cursor.getInt(cursor.getColumnIndexOrThrow("mon"));
if(mon == 1){
((TextView) view).setTextColor(Color.parseColor("#FFFFFF"));
}
return true;
}
if (columnIndex == tue_column) {
int tue = cursor.getInt(cursor.getColumnIndexOrThrow("tue"));
if(tue == 1){
((TextView) view).setTextColor(Color.parseColor("#FFFFFF"));
}
return true;
}
if (columnIndex == wed_column) {
int wed = cursor.getInt(cursor.getColumnIndexOrThrow("wed"));
if(wed == 1){
((TextView) view).setTextColor(Color.parseColor("#FFFFFF"));
}
return true;
}
if (columnIndex == thu_column) {
int thu = cursor.getInt(cursor.getColumnIndexOrThrow("thu"));
if(thu == 1){
((TextView) view).setTextColor(Color.parseColor("#FFFFFF"));
}
return true;
}
if (columnIndex == fri_column) {
int fri = cursor.getInt(cursor.getColumnIndexOrThrow("fri"));
if(fri == 1){
((TextView) view).setTextColor(Color.parseColor("#FFFFFF"));
}
return true;
}
if (columnIndex == sat_column) {
int sat = cursor.getInt(cursor.getColumnIndexOrThrow("sat"));
if(sat == 1){
((TextView) view).setTextColor(Color.parseColor("#FFFFFF"));
}
return true;
}
return false;
}
});
lv = (ListView) v.findViewById(R.id.listView);
lv.setAdapter(adapter);
Perhaps I am going about this all wrong ?? It nearly works though.
Many thanks
You still need to handle the cases where mon, tue, etc. == 0. Adding the following to each if statement should fix it:
else {
((TextView) view).setTextColor(//color that you want if day == 0);
}
Also, you may want to consider changing your whole setViewValue to use a switch statement, it should make the cod more readable.
Related
I have a code that every view will have a different background
When I scroll up and down then all the colors get confused and all the CheckBoxes markings change and when I erase a part, Then something else is erased and changed color.
tell me if you need The full code
this the code of Changed Background color:
View v = List.getChildAt(index -
List.getFirstVisiblePosition());
if(v == null)
return;
ConstraintLayout LayoutT = v.findViewById(R.id.LayoutT);
LayoutT.setBackgroundColor(Color.RED);
this code of delete:
CheckBox currentCheckBox = (CheckBox) view.findViewById(mCheckBoxView);
currentCheckBox.setChecked(mCheckBoxStates[csr.getPosition()]);
currentCheckBox.setTag(new Long(csr.getLong(csr.getColumnIndex(DatabaseHandler.KEY_ID))));
currentCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
final int position = fcsr.getPosition();
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mCheckBoxStates[position] = ((CheckBox) buttonView).isChecked();
int restore_cursor_position = fcsr.getPosition();
fcsr.moveToPosition(position);
fcsr.moveToPosition(restore_cursor_position); //restore the Cursor's position
}
});
another class:
for (long id : mCheckedIdList) {
mDBHandler.deleteRecord(id);
}
db.beginTransaction();
db.setTransactionSuccessful();
db.endTransaction();
mCsr = mDBHandler.getAllRecords();
mMCA.swapCursor(mCsr);
EDIT
I tried to do what you suggested at first. And it worked perfectly but when I adjusted it to my code then only one color appears, it changes depending on the last color or the first one that should appear
#Override
public View getView(int position, View view, ViewGroup parent) {
View convertview = super.getView(position, view,parent);
parent.setBackgroundColor(0xFF555555);
// LinearLayout ll = (LinearLayout)
convertview.findViewById(R.id.item_layout);
int[] colours = new int[]{
ContextCompat.getColor(mContext, R.color.Cyan)
, ContextCompat.getColor(mContext, R.color.LowRed)
};
if (convertview != null) {
DatabaseHandler db = new DatabaseHandler(mContext);
int Count = List.getCount();
String[] Status = new String[Count];
for (int i = 0; i < Count; ) {
Cursor c = db.getCursorStatus(i);
if (c != null) {
while (c.moveToNext()) {
Status[i] = c.getString(0);
}
}
String mStatus[] = new String[3];
mStatus[0] = "Monetary_Expenditure";
mStatus[1] = "Financial income";
mStatus[2] = "Cancellation";
boolean first = Status[i] != null && Status[i].equals(mStatus[1]);
boolean second = Status[i] != null && Status[i].equals(mStatus[0]);
if (Status[i] != null && Status[i].equals(mStatus[1])) {
convertview.setBackgroundColor(colours[1]);
} else if (Status[i] != null && Status[i].equals(mStatus[0])) {
convertview.setBackgroundColor(colours[0]);
}
else {convertview.setBackgroundColor(0xFF555555);}
i++;
}
}
return convertview;
}
edit 2
I changed it:
if (convertview != null) {
Cursor csr = getCursor();
String status = csr.getString(0);
int colourindex = 0;
if (status.equals("Financial income") {
colourindex = 1;
}
if (status.equals("Cancellation") {
colourindex = 2;
}
convertview.setBackgroundColor(colours[colourindex]);
}
to:
if (convertview != null) {
Cursor csrF = getCursor();
DatabaseHandler db = new DatabaseHandler(mContext);
i++;
Cursor csr = db.getCursorStatus(i);
String status = csr.getString(0);
int colourindex = 0;
if (status.equals("Financial income")) {
colourindex = 1;
}
if (status.equals("Cancellation")) {
colourindex = 2;
}
convertview.setBackgroundColor(colours[colourindex]);
}
Because the cursor did not turn to the right line
And I get this error: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
EDIT 3
Cursor csr = getCursor();
String status="";
while (csr.moveToNext()) {
status = csr.getString(4);
}
int colourindex = 3;
if ("Monetary Expenditure".equals(status)){
colourindex = 0;
}
else if ("Financial income".equals(status)) {
colourindex = 1;
}
else if ("Cancellation".equals(status)) {
colourindex = 2;
}
convertview.setBackgroundColor(colours[colourindex]);
Log.i("Debug", "colour index is: "+colourindex);
In your Custom Adapter override the getView() method and set the colour in that method.
The signature is :- public View getView(int position, View view, ViewGroup parent).
position is the position within the list of the view being processed.
view is the view (the layout)
parent is the ListView
The modified view should be returned.
An example, that changes the background colour (every x rows is a different colour where x is the number of colours) :-
#Override
public View getView(int position, View view, ViewGroup parent) {
View convertview = super.getView(position, view,parent);
parent.setBackgroundColor(0xFF555555);
//LinearLayout ll = (LinearLayout) convertview.findViewById(R.id.item_layout);
int[] colours = new int[]{0xFFFF55FF,0xBBFF55FF,0x77FF55FF};
if (convertview != null) {
convertview.setBackgroundColor(colours[position % colours.length]);
//ll.setBackgroundColor(colours[position % colours.length]);
}
return convertview;
}
parent.setBackgroundColor(0xFF555555); sets the background colour (darkish grey) of the ListView.
Commented out lines are an alternative means to get get the layout but aren't required
In this example the colours are the same but the transparency is increases thus letting the background (ListView/parent) colour to show.
The result (as per modification of the code provided in the answer provided to your previous question) :-
You could alternately override the bindView method, as that has the View passed to it, although it does not have the position passed. You could also use a combination of both.
Another Example of manipulating ListView colours
Here's a completer Custom Cursor Adapter that uses user defined colours extracted from the database to colour each item accordingly using bindView. However, this changes the drawable's background colour. It's for Credit Card management (work still in progress ), thus each item in the ListView looks like a Credit Card. :-
public class CardListViewCursorAdapter extends CursorAdapter {
Context mContext;
Cursor mCurssor;
CardListViewCursorAdapter(Context context, Cursor csr) {
super(context, csr, 0);
mContext = context;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
return super.getView(position, convertView, parent);
}
#Override
public View newView(Context context, Cursor csr, ViewGroup viewGroup) {
return LayoutInflater.from(context).inflate(
R.layout.standard_cards_listview,
viewGroup,
false
);
}
#Override
public void bindView(View view, Context context, Cursor csr) {
TextView mCardName = view.findViewById(R.id.scl_cardname);
TextView mCardNotes = view.findViewById(R.id.scl_cardnotes);
LinearLayout mCardLayout = view.findViewById(R.id.scl_cardlayout);
Drawable mDrawable = mCardLayout.getBackground();
int cardcolour = (int) CardManageActivity.DEFAULT_CARDCOLOUR;
long extracted_cardcolour = csr.getLong(
csr.getColumnIndex(
DBCardsTableConstants.CARDCOLOUR.getDBColumnName()
)
);
if ((extracted_cardcolour & DBCardsTableConstants.CARDSCOLOUR_FLAG) > 0) {
cardcolour = (int) extracted_cardcolour;
}
setShapeBackGroundColour(mDrawable, cardcolour);
mCardName.setText(
csr.getString(
csr.getColumnIndex(
DBCardsTableConstants.CARDNAME.getDBColumnName())
)
);
mCardNotes.setText(
csr.getString(
csr.getColumnIndex(
DBCardsTableConstants.CARDNOTES.getDBColumnName()
)
)
);
}
private void setShapeBackGroundColour(Drawable drawable, int colour) {
if (drawable instanceof ShapeDrawable) {
ShapeDrawable sd = (ShapeDrawable) drawable;
sd.getPaint().setColor(colour);
}
if (drawable instanceof GradientDrawable) {
GradientDrawable gd = (GradientDrawable) drawable;
gd.setColor(colour);
}
if (drawable instanceof ColorDrawable) {
ColorDrawable cd = (ColorDrawable) drawable;
cd.setColor(colour);
}
}
}
This looks like :-
Answer regarding :-
I edited the code as you said I tried to do what you suggested at
first. And it worked perfectly but when I adjusted it to my code then
only one color appears, it changes depending on the last color or the
first one that should appear And why what I tried was problems? And
thank you very much for everything
I believe that your problem is that within getView (which is called individually for each item in the list (as is bindView) the View being the View for that position in the list) you are the looping through all the items/views and basically changing ALL items to be as per the last item.
i.e. getView will be called (at least) 10 times for a list of 10 items. Each time it is called it is for the individual view/item being processed.
I believe you need to change :-
if (convertview != null) {
DatabaseHandler db = new DatabaseHandler(mContext);
int Count = List.getCount();
String[] Status = new String[Count];
for (int i = 0; i < Count; ) {
Cursor c = db.getCursorStatus(i);
if (c != null) {
while (c.moveToNext()) {
Status[i] = c.getString(0);
}
}
String mStatus[] = new String[3];
mStatus[0] = "Monetary_Expenditure";
mStatus[1] = "Financial income";
mStatus[2] = "Cancellation";
boolean first = Status[i] != null && Status[i].equals(mStatus[1]);
boolean second = Status[i] != null && Status[i].equals(mStatus[0]);
if (Status[i] != null && Status[i].equals(mStatus[1])) {
convertview.setBackgroundColor(colours[1]);
} else if (Status[i] != null && Status[i].equals(mStatus[0])) {
convertview.setBackgroundColor(colours[0]);
}
else {convertview.setBackgroundColor(0xFF555555);}
i++;
}
}
To :-
if (convertview != null) {
Cursor csr = getCursor();
String status = csr.getString(0);
int colourindex = 0;
if (status.equals("Financial income") {
colourindex = 1;
}
if (status.equals("Cancellation") {
colourindex = 2;
}
convertview.setBackgroundColor(colours[colourindex]);
}
So you get the cursor using the CursorAdapters getCursor() method, the cursor will be positioned accordingly.
You then extract the status for the item in the List for which the View is being built i.e. getView() is called for every item in the list. So if you have 10 items in the List getView() is called at least 10 times. You appear to consider that it is called just once.
The colour index (0,1 or 2) is determined according to the status (column 0).
The background colour is set according to the status for the specific Item in the list.
I'm a little bit stuck on viewbinders in android
here's my code:
public void displayAllAlerts() {
Cursor mCursor = mDbAdapter.fetchAllAlerts();
//Bind Columns
String[] columns = new String[] {
DbAdapter.KEY_ID,
DbAdapter.KEY_PLACE,
DbAdapter.KEY_LONG,
DbAdapter.KEY_LAT,
DbAdapter.KEY_STATUS
};
int[] to = new int[] {
R.id.txtId,
R.id.txtPlace,
R.id.txtLong,
R.id.txtLat,
R.id.tglBtnAlert
};
mSimpleCursorAdapter = new SimpleCursorAdapter(
this,
R.layout.layout_lvrow,
mCursor,
columns,
to,
0);
ListView lvAlerts = (ListView) findViewById(R.id.lvAlerts);
lvAlerts.setAdapter(mSimpleCursorAdapter);
}
The problem is that 'DbAdapter.key_status' is formatted as an int in my database, but someway I have to change it to a boolean, beacuase it's my status for my togglebutton.
I know i have to use .setViewBinder, but i have no idea were to start.
I tried the following from some tutorials but it does not work:
mSimplecursorAdapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
if (aColumnIndex == 5) {
String strBool = aCursor.getString(aColumnIndex);
ToggleButton tb = (Togglebutton) aView;
if (strBool=="0") {
tb.setChecked = false;
}else{
tb.setChecked = true;
}
return true;
}
return false;
}
thanks in advance
(also tried already to use developer site of android but it's giving me a real headache)
The code does not work because you must use String.equals() or TextUtils.equals() to compare strings.
To handle boolean columns on SQLite, I usually handle this data as INTEGER with values 1 or 0:
public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
if (aColumnIndex == 5) {
boolean checked = aCursor.getInt(aColumnIndex) == 1;
ToggleButton tb = (Togglebutton) aView;
tb.setChecked(checked);
return true;
}
return false;
}
I'm using multiple selection on the listview in my app which is being populated by db (SimpleCursorAdapter). There's some weird behavior with the listview selection.
If there are more than 7 items in the database, if I select the 1st item in the listview, the 8th item also gets selected even when I'm not selecting the 8th item and vice-versa. If I select the 9th item, the 2nd row gets selected.
What's happening here?
Code:
String[] projection = { ..table_columns..};
String[] from = { table_columns..};
Cursor cursor = contentResolver.query(SomeContentProvider.CONTENT_URI, projection, null, null,
null);
// the XML defined views which the data will be bound to
int[] to = new int[] {
R.id.color,
R.id.name,
R.id.desc,
};
// create the adapter using the cursor pointing to the desired data
//as well as the layout information
dataAdapter = new SimpleCursorAdapter(
this, R.layout.layout_main,
cursor,
from,
to,
0);
dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Cursor cursor, int column) {
int nNameIndex = cursor.getColumnIndexOrThrow(EventsTable.COLUMN_NAME);
if( column == nNameIndex ){
TextView nname = (TextView) view;
String name = cursor.getString(cursor.getColumnIndex(EventsTable.COLUMN_NAME));
String formatted_name = "NAME: " +name;
nname.setText(formatted_name);
return true;
}
return false;
}
});
listView.setAdapter(dataAdapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
if (!listView.isItemChecked(pos)){
listView.setItemChecked(pos, true);
v.setBackground(getResources().getDrawable(R.drawable.listview_bg_selected));
v.setSelected(true);
} else {
listView.setItemChecked(pos, false);
v.setBackground(getResources().getDrawable(R.drawable.listview_bg));
v.setSelected(false);
}
if (listView.getCheckedItemCount() > 0) {
if (mMode == null) {
mMode = startActionMode(new ActionModeCallback());
} else {
mMode.setTitle(listView.getCheckedItemCount() + " " + "Selected");
}
} else {
if (mMode != null) {
mMode.finish();
}
}
return true;
}
});
I suspect it's because in your bindView of your adapter you are not checking if the item is checked, and then changing the background appropriately.
You experiencing your views being recycled.
So when you scroll, and say item one goes out of view and was selected, the view for item 1 is reused for item 8.
SO add something like this to your view binder
int post = cursor.getPosition();
if (!listView.isItemChecked(pos)){
v.setBackground(getResources().getDrawable(R.drawable.listview_bg_selected));
} else {
v.setBackground(getResources().getDrawable(R.drawable.listview_bg));
}
I put a list of exercises in the lesson. The user can modify this exercise to show or not. When he clicks on the exercise, changing the status (show or not show) exercise.
All changes made to the database works fine. But when the user made the change, when you scroll through the picture "check" is displayed not correctly in emerging lines.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....
db = new MyDatabase(this);
getOnListExes();
db.close();
}
....
public void getOnListExes() {
onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
sAdapter = new SimpleCursorAdapter(this,
R.layout.exeslist, onListExesChek,
new String[] {"exes_bodypart", "exes_name", "exes_name"},
new int[] {R.id.exesPartlist_chek, R.id.exesNamelist_chek,
R.id.chek_img}) {
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
TextView exesPartlist_chek =
(TextView) row.findViewById(R.id.exesPartlist_chek);
TextView exesNamelist_chek =
(TextView) row.findViewById(R.id.exesNamelist_chek);
ImageView imageGender =
(ImageView) row.findViewById(R.id.chek_img);
return row;
}
};
sAdapter.setViewBinder(new MyViewBinder());
listExesChek.setAdapter(sAdapter);
}
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
positionChek = position;
selectExe_id = Long.toString(id);
db = new MyDatabase(this);
onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
onListExesChek.moveToPosition(positionChek);
if (
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()) {
if(prog_man.equals("1")) {
prog_man_chek = new ContentValues();
prog_man_chek.put("prog_man_chek", "0");
int upProg_man_chek = db.setExe(prog_man_chek,
selectExe_id);
}
if(prog_woman.equals("1")) {
prog_woman_chek = new ContentValues();
prog_woman_chek.put("prog_woman_chek", "0");
int upProg_woman_chek = db.setExe(prog_woman_chek,
selectExe_id);
} else {
if(prog_man.equals("1")) {
prog_man_chek = new ContentValues();
prog_man_chek.put("prog_man_chek", "1");
int upProg_man_chek = db.setExe(prog_man_chek,
selectExe_id);
}
if(prog_woman.equals("1")) {
prog_woman_chek = new ContentValues();
prog_woman_chek.put("prog_woman_chek", "1");
int upProg_woman_chek = db.setExe(prog_woman_chek,
selectExe_id);
}
}
db.close();
updateView(position);
}
void updateView(int index){
db = new MyDatabase(this);
onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
onListExesChek.moveToPosition(positionChek);
View v = listExesChek.getChildAt(index -
listExesChek.getFirstVisiblePosition());
if (
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()
) {
ImageView imageGender = (ImageView) v.findViewById(R.id.chek_img);
imageGender.setImageResource(R.drawable.check);
} else {
ImageView imageGender = (ImageView) v.findViewById(R.id.chek_img);
imageGender.setImageResource(R.drawable.notchek);
}
db.close();
}
class MyViewBinder implements SimpleCursorAdapter.ViewBinder {
public boolean setViewValue (View view, Cursor cursor, int columnIndex) {
switch (view.getId()) {
case R.id.chek_img:
if (onListExesChek.getInt(onListExesChek.
getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()
) {
((ImageView) view).setImageResource(R.drawable.check);
} else {
(
(ImageView) view).setImageResource(R.drawable.notchek);
}
return true;
}
return false;
}
}
It's a side-effect of ListView's view recycling. You're not setting a default resource in the getView method so the ImageView will "keep" whatever you set it to in the updateView method. This effect is really noticeable in longer lists where you'll see a repeating incorrect state.
You should be able to fix this by setting the state of the ImageView within your getView method.
ListViews recycle views, which means at first a base set of list entries is inflated from XML.
for more check
android listview displays false data after scrolling (custom adapter)
ListView is not showing correct values after scrolling
both works for me
http://i.imgur.com/PyO4q.png?1
This image is using the gridview to make a calendar, but now I want to add a new event in "day". So I thought to use the listview inside the gridview-day, but the problem is the listview doesn't scroll. I think maybe the listview scroll collides with gridview. Please give me some idea to solve this problem.
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
TextView dayView;
TextView present;
TextView meeting;
TextView other;
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);
present=(TextView)v.findViewById(R.id.ptextView1);
meeting=(TextView)v.findViewById(R.id.mtextView2);
other=(TextView)v.findViewById(R.id.otextView3);
// listitem=(ListView)v.findViewById(R.id.calendarlist);
// listitem.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
// 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]);
present.setVisibility(View.GONE);
meeting.setVisibility(View.GONE);
other.setVisibility(View.GONE);
for(int t=0;t<date1.size();t++){
if(returndouble(dayView.getText().toString()).equals(date1.get(t).get(3))){
if(date1.get(t).get(1).equals("Presented")){
meeting.setVisibility( View.VISIBLE);
}else if(date1.get(t).get(1).equals("Present")){
present.setVisibility( View.VISIBLE);
}else{
other.setVisibility( View.VISIBLE);
}
}
}
// 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;
}
public void refreshDays()
{
// clear items
items.clear();
Calendardb date=new Calendardb(mContext);
date1= date.calendarselect(String.valueOf( month.get(Calendar.YEAR))+"/"+returndouble(String.valueOf((month.get(Calendar.MONTH)+1))));
int lastDay = month.getActualMaximum(Calendar.DAY_OF_MONTH);
int firstDay = (int)month.get(Calendar.DAY_OF_WEEK);
// figure size of the array
if(firstDay==1){
days = new String[lastDay+(FIRST_DAY_OF_WEEK*6)];
}
else {
days = new String[lastDay+firstDay-(FIRST_DAY_OF_WEEK+1)];
}
int j=FIRST_DAY_OF_WEEK;
// populate empty days before first real day
if(firstDay>1) {
for(j=0;j<firstDay-FIRST_DAY_OF_WEEK;j++) {
days[j] = "";
}
}
else {
for(j=0;j<FIRST_DAY_OF_WEEK*6;j++) {
days[j] = "";
}
j=FIRST_DAY_OF_WEEK*6+1; // sunday => 1, monday => 7
}
// populate days
int dayNumber = 1;
for(int i=j-1;i<days.length;i++) {
days[i] = ""+dayNumber;
dayNumber++;
}
}