-
Notifications
You must be signed in to change notification settings - Fork 0
/
CO 03 - Question 05.txt
47 lines (34 loc) · 1.87 KB
/
CO 03 - Question 05.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
------------------------------------------------------------------- XML Code -------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
------------------------------------------------------------------- Java Code -------------------------------------------------------------------
package com.example.arrayadapter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listview;
String[] person_qualify = {"Front-End Developer", "Data Analyst", "Software Tester", "Software Developer", "Programming Analyst", "Web Developer", "Mobile App Developer", "Business Analyst", "Database Analyst"};
listview = findViewById(R.id.listview);
listview.setAdapter(new ArrayAdapter(getApplicationContext(), android.R.layout.simple_expandable_list_item_1, person_qualify));
listview.setOnItemClickListener((parent, view, position, id) -> {
Toast.makeText(this, "The qualification selected is - " + person_qualify[position], Toast.LENGTH_SHORT).show();
});
}
}