SlideShare a Scribd company logo
1 of 2
Main activity java:
package com.example.listview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.text.DateFormatSymbols;
public class MainActivity extends AppCompatActivity {
ListView lvMonth;
String[] months;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvMonth = findViewById(R.id.lvMonth);
months = new DateFormatSymbols().getMonths();
ArrayAdapter<String> monthAdapter =new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, months);
lvMonth.setAdapter(monthAdapter);
}
}
Activity_main_XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
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"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="simple list view"
android:textColor="@android:color/holo_blue_dark"
android:textSize= "32dp"
android:layout_marginBottom="5dp"
/>
<ListView
android:id="@+id/lvMonth"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.appcompat

More Related Content

More from university of Gujrat, pakistan

More from university of Gujrat, pakistan (20)

Change management
Change management Change management
Change management
 
Latest Trends in Digital Marketing
Latest Trends in Digital MarketingLatest Trends in Digital Marketing
Latest Trends in Digital Marketing
 
Dark web (2)
Dark web (2)Dark web (2)
Dark web (2)
 
Code of ethics and professional conduct (1)
Code of ethics and professional conduct (1)Code of ethics and professional conduct (1)
Code of ethics and professional conduct (1)
 
Certification accreditation and licensure (1)
Certification accreditation and licensure (1)Certification accreditation and licensure (1)
Certification accreditation and licensure (1)
 
biggest technology trends
biggest technology trendsbiggest technology trends
biggest technology trends
 
Freedom of information (1)
Freedom of information (1)Freedom of information (1)
Freedom of information (1)
 
Individual cognition ppt (1)
Individual cognition ppt (1)Individual cognition ppt (1)
Individual cognition ppt (1)
 
Top 10 highest (1)
Top 10 highest (1)Top 10 highest (1)
Top 10 highest (1)
 
creativity and imagination
creativity and imagination creativity and imagination
creativity and imagination
 
Brainstorming 078 (1)
Brainstorming 078 (1)Brainstorming 078 (1)
Brainstorming 078 (1)
 
speeh-artificial intelligemce
speeh-artificial intelligemce speeh-artificial intelligemce
speeh-artificial intelligemce
 
Pp dealing with problem complexity (1)
Pp dealing with problem complexity (1)Pp dealing with problem complexity (1)
Pp dealing with problem complexity (1)
 
Motivation
MotivationMotivation
Motivation
 
Vision of artificial intelligence (1)
Vision of artificial intelligence (1)Vision of artificial intelligence (1)
Vision of artificial intelligence (1)
 
Entrepreneurship (1)
Entrepreneurship (1)Entrepreneurship (1)
Entrepreneurship (1)
 
Role of professional societies
Role of professional societiesRole of professional societies
Role of professional societies
 
Dealing with culticultural environment (1)
Dealing with culticultural environment (1)Dealing with culticultural environment (1)
Dealing with culticultural environment (1)
 
Dealing with problem complexity (1)
Dealing with problem complexity (1)Dealing with problem complexity (1)
Dealing with problem complexity (1)
 
cyber security and cyber crime
cyber security and cyber crime cyber security and cyber crime
cyber security and cyber crime
 

List view months

  • 1. Main activity java: package com.example.listview; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; import java.text.DateFormatSymbols; public class MainActivity extends AppCompatActivity { ListView lvMonth; String[] months; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lvMonth = findViewById(R.id.lvMonth); months = new DateFormatSymbols().getMonths(); ArrayAdapter<String> monthAdapter =new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, months); lvMonth.setAdapter(monthAdapter); } } Activity_main_XML: <?xml version="1.0" encoding="utf-8"?> <androidx.appcompat.widget.LinearLayoutCompat 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" android:orientation="vertical" android:gravity="center" android:padding="16dp" > <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="simple list view" android:textColor="@android:color/holo_blue_dark" android:textSize= "32dp" android:layout_marginBottom="5dp" /> <ListView