Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.carloschaves.alugar000
- import android.content.Context
- import android.graphics.Color
- import android.support.v7.app.AppCompatActivity
- import android.os.Bundle
- import android.view.View
- import android.view.ViewGroup
- import android.widget.BaseAdapter
- import android.widget.ListView
- import android.widget.TextView
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- val listView = findViewById<ListView>(R.id.main_listview)
- val redColor = Color.parseColor( "#FF0000")
- listView.setBackgroundColor(redColor)
- listView.adapter = MyCustomAdapter( this) // this needs to be my custom adapter telling my list what to rendering
- }
- private class MyCustomAdapter (context: Context): BaseAdapter() {
- private val mContext: Context
- init {
- mContext = context
- }
- // responsible for how many rows in may list
- override fun getCount(): Int {
- return 5
- }
- //you can also ignore this
- override fun getItemId(position: Int): Long{
- return position.toLong()
- }
- //you can ignore this for now
- override fun getItem(position: Int): Any {
- return "Test String"
- }
- // responsible for rendering out each row
- override fun getView(position: Int, convertView: View?, viewGroup: ViewGroup?): View {
- val textView = TextView(mContext)
- textView.text = "Here is my Row for my listview"
- return textView
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement