Practical 8a
Practical 8a
activity_practical_no8a.xml
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="0dp" android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- Pickup Location -->
<EditText
android:id="@+id/pickupLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Pickup Location"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mapView" />
</androidx.constraintlayout.widget.ConstraintLayout>
PracticalNo8a.kt
package com.example.parcticaltyit
if (ActivityCompat.checkSelfPermission(
this, Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission( this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
){
ActivityCompat.requestPermissions(
this, arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
),
LOCATION_PERMISSION_REQUEST_CODE
)
return
}
if (cursor.moveToFirst()) {
do {
val pickup =
cursor.getString(cursor.getColumnIndex(RideDatabaseHelper.COLUMN_PICKUP))
val destination =
cursor.getString(cursor.getColumnIndex(RideDatabaseHelper.COLUMN_DESTINATION))
val fare =
cursor.getString(cursor.getColumnIndex(RideDatabaseHelper.COLUMN_FARE))
rideList.add("From: $pickup\nTo: $destination\nFare: $fare")
} while (cursor.moveToNext())
} cursor.close()
rideListAdapter.notifyDataSetChanged()
}
Create a new ‘Empty Activity’ from App -> New -> Activity -> Empty Activity and name it
as shown below. Let its xml file be default.
RideDatabaseHelper.kt
package com.example.uber
Output:
Conclusion: This program has been implemented and executed successfully.