List Views - Hallo sahabat Google Android Developer Tutorial, Pada Artikel yang anda baca kali ini dengan judul List Views, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan
Artikel List view with background color changing for an item selected, yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.
Judul : List Views
link : List Views
6 .Run the application in the emulator.
Anda sekarang membaca artikel List Views dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2012/09/list-views.html
Judul : List Views
link : List Views
List Views
LIST VIEW Tutorial
ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.
ListActivity
ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results.
The Demonstrative project lists a set of Bond films and various list selection features
ListActivity
ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results.
The Demonstrative project lists a set of Bond films and various list selection features
1.Create Android project with details as listed in table below
Property name | Property value |
Project name | SRM_UIExamples |
Package name | in.ac.srmuniv |
Activity name | ListViewsExample |
Layout xml name | listview |
2.Copy the code to the file listview.xml in res/layout folder
<?xml version="1.0"encoding="utf-8"?>
<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/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:dividerHeight="2dp"
android:listSelector="@drawable/listrow_selection"/></LinearLayout>
3 a.Copy the code rowlist_bg.xml in res/drawable-hdpi folder.
3 a.Copy the code rowlist_bg.xml in res/drawable-hdpi folder.
<?xml version="1.0"encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#f35edd"
android:centerColor="#f44173"
android:endColor="#f52a1e"
android:centerColor="#f44173"
android:endColor="#f52a1e"
android:angle="270" />
</shape>
3 b.Copy the code rowlist_hover.xml in res/drawable-hdpi folder.
<?xml version="1.0"encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#faf72e"
android:centerColor="#bdf743"
android:endColor="#44f760"
android:centerColor="#bdf743"
android:endColor="#44f760"
android:angle="270" />
</shape>
3 c.Copy the code rowlist_border.xml in res/drawable-hdpi folder.
<?xml version="1.0"encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp"android:color="#dbdbdc" />
<solid android:color="#FFFFFF"/>
</shape>
</item>
</layer-list>
3 d.Copy the code rowlist_selection.xml in res/drawable-hdpi folder.
<?xml version="1.0"encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:drawable="@drawable/listrow_bg" />
<item android:state_pressed="true"
android:drawable="@drawable/listrow_hover" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/listrow_hover" />
</selector>
4.Copy the code in ListViewsExample.java Activity.
package in.ac.srmuniv;
import android.os.Bundle;
import android.view.View;
importandroid.widget.ArrayAdapter;
importandroid.widget.ListView;
importandroid.widget.Toast;
importandroid.app.ListActivity;
public class ListViewsExample extends ListActivity {
String[] bond_films = { "Dr.No", "Man with Golden gun",
"You only Live twice", "Live and Let die", "Thunderball",
"License to Kill", "From Russia with Love", "Moonraker",
"Octopussy", "A View to Kill", "On Her Majesty Service",
"Golden Eye"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
setListAdapter(newArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, bond_films));
}
public voidonListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this, "You have selected " + bond_films[position],
Toast.LENGTH_SHORT).show();
}
}
5.No need to modify Androidmanifest.xml
. Figure 1 shows the ListView view in action. When an item is selected, a message will be displayed. Click on an item. A message containing the item selected will be displayed.
Customizing the ListView
ListView is a versatile view that you can further customize.You can change the background of the
list row item when selected or pressed to make a lively look.XML resource files in drawable folder provides gradient backround with appropriate RGB values entered.The following ListView property entry ensures selection of background in list view row when pressed and released after selection,
list row item when selected or pressed to make a lively look.XML resource files in drawable folder provides gradient backround with appropriate RGB values entered.The following ListView property entry ensures selection of background in list view row when pressed and released after selection,
android:listSelector="@drawable/listrow_selection"
The following code added to your code allow multiple items in the ListView to be selected and how you can enable filtering support.TEnabling Filtering and Multi-Item Support in the ListView1. Using the ListViewActivity created in the previous section, add the following statements in
bold to the ListviewExample.java file:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//---no need to call this---
//setContentView(R.layout.main);
ListView lstView = getListView();
//lstView.setChoiceMode(ListView.CHOICE_MODE_NONE);
//lstView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lstView.setTextFilterEnabled(true);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, bond_films));
}
2. Run the application on the Android emulator. You can now click on each item to
Demikianlah Artikel List Views
Sekianlah artikel List Views kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel List Views dengan alamat link https://googleandroiddevelopertutorial.blogspot.com/2012/09/list-views.html
List Views
4/
5
Oleh
Unknown