ListView
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class HelloListViewActivity extends ListActivity {
/** Called when the activity is first created. */
TextView t1;
ArrayAdapter<String> ad;
String str[]={"jisho","rahul", "Ajumal"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ad=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,str);
setListAdapter(ad);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Toast.makeText(this, str[position], Toast.LENGTH_LONG).show();
super.onListItemClick(l, v, position, id);
}
}
_____________________________________________________________________________
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ListView
android:id="@+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
No comments :
Post a Comment