Display all stop's when selected path
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
package com.example.busroute
|
||||
|
||||
import android.location.Address
|
||||
import android.location.Geocoder
|
||||
import android.os.Bundle
|
||||
import android.provider.BaseColumns
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.AdapterView.OnItemSelectedListener
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Spinner
|
||||
import android.widget.TableLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.view.menu.MenuBuilder.ItemInvoker
|
||||
import com.example.busroute.DataClass.PathList
|
||||
import com.example.busroute.Database.DbHelper
|
||||
import com.example.busroute.Database.PathContract
|
||||
import com.example.busroute.Database.StopContract
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
class PathToMaps: AppCompatActivity() {
|
||||
|
||||
@@ -16,6 +26,7 @@ class PathToMaps: AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
val dbHelper = DbHelper(this)
|
||||
val db = dbHelper.readableDatabase
|
||||
val geocoder = Geocoder(this, Locale.getDefault())
|
||||
setContentView(R.layout.select_path)
|
||||
|
||||
|
||||
@@ -42,8 +53,41 @@ class PathToMaps: AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
cursor.close()
|
||||
val stopTable = findViewById<TableLayout>(R.id.stop_table)
|
||||
val comboPath = findViewById<Spinner>(R.id.combo_path)
|
||||
comboPath.adapter = ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item, items)
|
||||
comboPath.onItemSelectedListener = object : OnItemSelectedListener {
|
||||
override fun onItemSelected(
|
||||
parentView: AdapterView<*>?,
|
||||
selectedItemView: View,
|
||||
position: Int,
|
||||
id: Long
|
||||
) {
|
||||
stopTable.removeAllViews()
|
||||
val selectedPath = parentView!!.selectedItem
|
||||
if(selectedPath != null){
|
||||
val cursor = db.rawQuery("SELECT * " +
|
||||
"FROM stop " +
|
||||
"WHERE path_id = ${(selectedPath as PathList).id} " +
|
||||
"ORDER BY 'order' ",
|
||||
arrayOf()
|
||||
)
|
||||
with(cursor) {
|
||||
while (moveToNext()) {
|
||||
val latitude = getDouble(getColumnIndexOrThrow(StopContract.StopEntry.LATITUDE))
|
||||
val longitude = getDouble(getColumnIndexOrThrow(StopContract.StopEntry.LONGITUDE))
|
||||
val text = TextView(comboPath.context)
|
||||
val geoResults: MutableList<Address>? = geocoder.getFromLocation(latitude, longitude, 1)
|
||||
text.text = "$latitude | $longitude\r${geoResults?.get(0)?.getAddressLine(0)}\n"
|
||||
stopTable.addView(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parentView: AdapterView<*>?) {
|
||||
// your code here
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,9 @@
|
||||
<Spinner
|
||||
android:id="@+id/combo_path">
|
||||
</Spinner>
|
||||
<TableLayout
|
||||
android:id="@+id/stop_table"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</TableLayout>
|
||||
Reference in New Issue
Block a user