create a gridview viewholder

This commit is contained in:
tibbi 2017-01-15 23:05:25 +01:00
parent ab4964db5f
commit 952df754a4
3 changed files with 20 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import com.simplemobiletools.calendar.fragments.WeekFragment
class MyWeekPagerAdapter(fm: FragmentManager, private val mListener: WeekFragment.WeekScrollListener) : FragmentStatePagerAdapter(fm) { class MyWeekPagerAdapter(fm: FragmentManager, private val mListener: WeekFragment.WeekScrollListener) : FragmentStatePagerAdapter(fm) {
private val mFragments = SparseArray<WeekFragment>() private val mFragments = SparseArray<WeekFragment>()
override fun getCount() = 3 override fun getCount() = 1
override fun getItem(position: Int): Fragment { override fun getItem(position: Int): Fragment {
val bundle = Bundle() val bundle = Bundle()

View File

@ -6,17 +6,31 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.BaseAdapter import android.widget.BaseAdapter
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.models.Event
class WeekEventsAdapter(val context: Context) : BaseAdapter() { class WeekEventsAdapter(val context: Context, val mEvents: List<Event>) : BaseAdapter() {
private val mInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater private val mInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
return mInflater.inflate(R.layout.week_grid_item, parent, false) var view = convertView
val viewHolder: ViewHolder
if (view == null) {
view = mInflater.inflate(R.layout.week_grid_item, parent, false)
viewHolder = ViewHolder(view)
view!!.tag = viewHolder
} else {
viewHolder = view.tag as ViewHolder
}
return view
} }
override fun getItem(position: Int) = null override fun getItem(position: Int) = mEvents[position]
override fun getItemId(position: Int) = 0L override fun getItemId(position: Int) = 0L
override fun getCount() = 24 * 7 override fun getCount() = 24 * 7
internal class ViewHolder(view: View)
} }

View File

@ -15,6 +15,7 @@ import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.views.MyScrollView import com.simplemobiletools.calendar.views.MyScrollView
import kotlinx.android.synthetic.main.fragment_week.view.* import kotlinx.android.synthetic.main.fragment_week.view.*
import org.joda.time.DateTime import org.joda.time.DateTime
import java.util.*
class WeekFragment : Fragment(), WeeklyCalendar { class WeekFragment : Fragment(), WeeklyCalendar {
private var mListener: WeekScrollListener? = null private var mListener: WeekScrollListener? = null
@ -37,7 +38,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
} }
}) })
mView.week_events_grid.adapter = WeekEventsAdapter(context) mView.week_events_grid.adapter = WeekEventsAdapter(context, ArrayList<Event>())
mCalendar = WeeklyCalendarImpl(this, context) mCalendar = WeeklyCalendarImpl(this, context)
return mView return mView