/* This is Simple Listview Demo of Android */
main.xml
<?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/lstDemo"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
ListViewDemoActivity.java
package com.listviewdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ListViewDemoActivity extends Activity {
/** Called when the activity is first created. */
String[] data = {"Item1","Item2","Item3","Item4","Item5","Item6","Item7","Item8","Item9","Item10"};
ListView lsDemo;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lsDemo=(ListView)findViewById(R.id.lstDemo);
ArrayAdapter<String> lstAdapter = new ArrayAdapter<String>(ListViewDemoActivity.this,android.R.layout.simple_list_item_1, data);
lsDemo.setAdapter(lstAdapter);
lsDemo.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(ListViewDemoActivity.this, parent.getItemAtPosition(position).toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
1 comments:
Bro,,,You dont knw how much dis has helpled me....thankuuuuu you....a lot..
Post a Comment