Android example to create listView using String.xml

      No Comments on Android example to create listView using String.xml

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:entries="@array/scanf" >
    </ListView>

</LinearLayout>

MAinActivity.java

package com.example.listview;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity 
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}

Strings.xml

res/values/folder

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">List View</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    
    <string-array name="scanf">
    <item>C++</item>
    <item>Android</item>
    <item>Php</item>
    <item>Html</item>
    <item>Css</item>
    <item>Java</item>
</string-array>
</resources>

OUTPUT:-

Leave a Reply

Your email address will not be published. Required fields are marked *