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);
}
}
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" />
0 comments:
Post a Comment