0% found this document useful (0 votes)
26 views

List View

Uploaded by

abeni mesfin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

List View

Uploaded by

abeni mesfin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//LIST View in android

//activity_main.xml
<TextView android:text="UUHMS Services"
android:textSize="19sp"
android:textColor="@color/material_blue_grey_800"
android:layout_marginLeft="60dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/lv"
android:layout_marginTop="60dp"
android:layout_width="wrap_content"
android:layout_height="match_parent" />

----------------------------------------------------------
//MainActivity.java class

package com.example.cyber.listnew;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


ListView lv;
String[]
UUhms={"COVID19","Anthrax","Infection","Asthma","BPD","Ostoarthrithis","Acne","Alle
rgies","Anxiety","Chest pain"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv= (ListView) findViewById(R.id.lv);

//ADAPTER
ArrayAdapter<String> adapter=new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,UUhms);
lv.setAdapter(adapter);

//LISTENER
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i,
long l) {
Toast.makeText(MainActivity.this, UUhms[i],
Toast.LENGTH_SHORT).show();
}
});

You might also like