How to create Android ListView

Android ListView

Android ListView



ListView.java

package com.example.admin.listview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;

public class ListView extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);
        String[] stringArray={"samsung","sony","intex","apple","microsoft","lenovo","nokia","micromax","aoc"};
        ArrayAdapter adapter=new ArrayAdapter<String>(this,R.layout.list_layout,stringArray);
        android.widget.ListView listView= (android.widget.ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
    }
}


Layouts
activity_list_view.xml

<LinearLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
</LinearLayout>


list_layout.xml
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android" />

Share on Google Plus

About Mayank Sharma

Mayadi is a knowlage source. You can learn, explore and play many things in a proper way. Mayadi Provides Best, Perfect and Quality Information. subscribe our youtube channel to be updated and and don't forget to take a look on our blog within every week, because we are here to upgrade your knowladge. We love to see you again and again and again...
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment