Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

based on this xml file and java file edit the xml so the program runs as the demo video below https://watch.screencastify.com/v/cGwSMTeNi53Bpzdo2hRK) package com.example.midterm1_part2; import androidx.appcompat.app.AppCompatActivity;

based on this xml file and java file edit the xml so the program runs as the demo video below

https://watch.screencastify.com/v/cGwSMTeNi53Bpzdo2hRK)

package com.example.midterm1_part2; import androidx.appcompat.app.AppCompatActivity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private TextView Header; ListView listView; String[] streamList = {"Science", "Accounting", "Arts", "Computing Science"}; private android.app.AlertDialog.Builder builder; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize the ListView and set its adapter ListView listView = findViewById(R.id.list_view); String[] streams = {"Science", "Accounting", "Arts", "Computing Science"}; ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, streams); listView.setAdapter(adapter); // Set the long click listener on the ListView items listView.setOnItemLongClickListener((parent, view, position, id) -> { // Create a new AlertDialog AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("Course details"); // Set the message based on the selected stream String stream = adapter.getItem(position); String message = ""; if (stream.equals("Science")) { message = "Physics, Chemistry, Atmospheric Sciences, Soil ecology."; } else if (stream.equals("Accounting")) { message = "Commerce, Economics, Maths, Statistics."; } else if (stream.equals("Arts")) { message = "Sociology, Political Science, History, Psychology."; } else if (stream.equals("Computing Science")) { message = "Maths, Programming 1, Microeconomics, Professional Writing."; } builder.setMessage(message); // Set the positive button and its click listener builder.setPositiveButton("Add to schedule", (dialog, which) -> { Toast.makeText(MainActivity.this, "Courses Successfully added to schedule", Toast.LENGTH_SHORT).show(); }); // Set the neutral button and its click listener builder.setNeutralButton("Select again", (dialog, which) -> { dialog.dismiss(); }); // Show the AlertDialog builder.show(); return true; }); } } 

xml file

    

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

LO2 Discuss the constraints faced in a typical recruitment process.

Answered: 1 week ago