Last active
February 9, 2024 07:34
-
-
Save sunmeat/53294261b667e64a5c0ea934bd44ca28 to your computer and use it in GitHub Desktop.
listview android example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AndroidManifest.xml: | |
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<application | |
... | |
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar" | |
... | |
================================================================================== | |
values\themes.xml: | |
<resources> | |
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<item name="android:windowBackground">@color/white</item> | |
<item name="android:textColor">@color/black</item> | |
</style> | |
... | |
================================================================================== | |
activity_main.xml: | |
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<ListView | |
android:id="@+id/list1" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> | |
================================================================================== | |
MainActivity.java: | |
package com.sunmeat.myapplication; | |
import android.os.Bundle; | |
import android.widget.ArrayAdapter; | |
import android.widget.ListView; | |
import androidx.appcompat.app.AppCompatActivity; | |
public class MainActivity extends AppCompatActivity { | |
ListView list; | |
ArrayAdapter<String> adapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
list = findViewById(R.id.list1); | |
String data[] = {"Apple", "Banana", "Coconut", "Lemon"}; | |
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, data); | |
list.setAdapter(adapter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment