Make ListView Menu on android

on Thursday, January 3, 2013 | 4:31 PM


ListView is a menu of the most commonly used in making much application android application. List view is a set list of data displayed and can scroll vertically. The whole point of making the ListView is that we will call a list of lists that we will be disposed to an array, then fed into the adapter of the widget listVew.

Here are the steps.

1. Create new project

2. Interface Design

We can design the interface as beautiful as possible, but in this discussion we will only show a seasoned beauty listview without the other.

in the project explorer in eclipse select res -> layout -> main.xml
add script listview.
<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:divider="#333333" android:dividerheight="0.2dip" android:id="@+id/list" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent"></listview>
</linearlayout>
in the script that we see we added a listview with name ID "list" that will be submitted to R, we adjust the height and width to cover parentnya (linear layout).

3. Call the main.java.
after designing the interface, we will call xml for show.
src -> main.java
The first step we must defined array to be inserted into the imageView.
protected String[] phone = new String[] {
      "Samsung",
      "Nokia",
      "Sony Ericson",
      "HTC",
      "Motorola"
      };
Array "phone" will be used as a navigation menu on the list.
Call the ImageView widget based on id's in the list by last main.xml ID "list".
ListView mainList = (ListView) findViewById(R.id.list);
set imageView adapter with list di array "phone".
mainList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, phone));
Run.

listview android

Adding Event klik
Here we will make the event type one item from the list is clicked, it will display a toast message. The step is to add a few lines of script.
mainList.setOnItemClickListener(new OnItemClickListener() {
 @Override
 public void onItemClick(AdapterView parent, View view, int position,
   long id) {
  // TODO Auto-generated method stub
  Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
            Toast.LENGTH_SHORT).show();
 }
});
Share this post :
Make ListView Menu on android Published By Technoledge Terima Kasih Telah membaca Make ListView Menu on android
Link Published on: 2013-01-03T16:31:00+07:00
ListView is a menu of the most commonly used in making much application android application. List view is a set list of data displayed and ... Rating 5 ★★★★★ Reviews 1110
Index »

Android App

 
Copyright © 2013. Technoledge - All Rights Reserved
Proudly powered by Blogger