diff --git a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java index 8a6aae4..63c4b4e 100644 --- a/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java +++ b/caldroid/src/main/java/com/roomorama/caldroid/CaldroidGridAdapter.java @@ -35,8 +35,8 @@ public class CaldroidGridAdapter extends BaseAdapter { // Use internally, to make the search for date faster instead of using // indexOf methods on ArrayList - protected HashMap disableDatesMap = new HashMap(); - protected HashMap selectedDatesMap = new HashMap(); + protected HashMap disableDatesMap = new HashMap<>(); + protected HashMap selectedDatesMap = new HashMap<>(); protected DateTime minDateTime; protected DateTime maxDateTime; @@ -59,6 +59,8 @@ public class CaldroidGridAdapter extends BaseAdapter { */ protected HashMap extraData; + protected LayoutInflater localInflater; + public void setAdapterDateTime(DateTime dateTime) { this.month = dateTime.getMonth(); this.year = dateTime.getYear(); @@ -148,6 +150,10 @@ public CaldroidGridAdapter(Context context, int month, int year, // Get data from caldroidData populateFromCaldroidData(); + + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + localInflater = CaldroidFragment.getLayoutInflater(context, inflater, themeResource); } /** @@ -309,7 +315,7 @@ protected void customizeTextView(int position, CellView cellView) { cellView.refreshDrawableState(); // Set text - cellView.setText("" + dateTime.getDay()); + cellView.setText(String.valueOf(dateTime.getDay())); // Set custom color if required setCustomResources(dateTime, cellView, cellView); @@ -336,26 +342,21 @@ public long getItemId(int arg0) { return 0; } - @Override - public View getView(int position, View convertView, ViewGroup parent) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - CellView cellView = (CellView) convertView; - - LayoutInflater localInflater = CaldroidFragment.getLayoutInflater(context, inflater, themeResource); - - // For reuse - if (convertView == null) { - if (squareTextViewCell) { - cellView = (CellView) localInflater.inflate(R.layout.square_date_cell, null); - } else { - cellView = (CellView) localInflater.inflate(R.layout.normal_date_cell, null); - } - } + @Override + public View getView(int position, View convertView, ViewGroup parent) { + CellView cellView; - customizeTextView(position, cellView); + // For reuse + if (convertView == null) { + final int squareDateCellResource = squareTextViewCell ? R.layout.square_date_cell : R.layout.normal_date_cell; + cellView = (CellView) localInflater.inflate(squareDateCellResource, parent, false); + } else { + cellView = (CellView) convertView; + } - return cellView; - } + customizeTextView(position, cellView); + + return cellView; + } }