Open your activity_main and paste below code.
Open your MainActivity and paste below code.
Output :
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/activity_main" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.ravindra.listviewdemo.MainActivity"> | |
<ListView | |
android:id="@+id/simplelist" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
</ListView> | |
</RelativeLayout> |
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
package com.ravindra.listviewdemo; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.ArrayAdapter; | |
import android.widget.ListView; | |
public class MainActivity extends AppCompatActivity { | |
//String Array for list item | |
String []item={"Cupcake"," Donut", | |
" Eclairs"," Froyo"," GingerBread"," HoneyComb", | |
" IceCreamSandWitch"," Jellybean"," Kitkat", | |
" Lollipop", "Marshmallow", "Nougat"}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ListView listview= (ListView) findViewById(R.id.simplelist); | |
// arrayadapter for listview | |
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,item); | |
//set adaapter to listview | |
listview.setAdapter(adapter); | |
} | |
} |
Output :
No comments:
Post a Comment