ListActivity.java
package com.android.first;
import java.util.Arrays;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ListActivity extends ListActivity {
String
item[]={
"ganesh","murali","vijaya","rengarajan","karthi" };
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Arrays.sort(item);
//
no more this
//
setContentView(R.layout.list_fruit);
setListAdapter(new
ArrayAdapter<String>(this, R.layout.list_data,item));
ListView
listView = getListView();
listView.setTextFilterEnabled(true);
final
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setTitle("Content");
listView.setOnItemClickListener(new
OnItemClickListener() {
public
void onItemClick(AdapterView<?> parent, View view,
int
position, long id) {
if("ganesh".equals(((TextView)
view).getText()))
{
adb.setMessage(R.string.ganesh);
adb.setIcon(R.drawable.icon);
adb.show();
}
else
if("murali".equals(((TextView) view).getText()))
{
adb.setMessage(R.string.murali);
adb.setIcon(R.drawable.icon);
adb.show();
}
else
if("vijaya".equals(((TextView) view).getText()))
{
adb.setMessage(R.string.vijaya);
adb.setIcon(R.drawable.icon);
adb.show();
}
else
if("rengarajan".equals(((TextView) view).getText()))
{
adb.setMessage(R.string.rengarajan);
adb.setIcon(R.drawable.icon);
adb.show();
}
else if("karthi".equals(((TextView) view).getText()))
{
adb.setMessage(R.string.karthi);
adb.setIcon(R.drawable.icon);
adb.show();
}
else
{
adb.setMessage(R.string.notfound);
adb.setIcon(R.drawable.icon);
adb.show();
}
}
});
}
}
List_data.xml
<?xml version="1.0"
encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="20sp" >
</TextView>
String.xml
<?xml version="1.0"
encoding="utf-8"?>
<resources>
<string name="hello">ganesh</string>
<string name="app_name">GaneshRengarajan</string>
<string name="ganesh">Author of Blog</string>
<string name="murali">1st brother
of ganesh<string>
<string name="vijaya">Mother
of ganesh</string>
<string name="Rengarajan">Father of ganesh</string>
<string name="karthi">2nd brother of ganesh </string>
<string name="notfound">Not Found</string>
</resources>
Snapshot
0 comments:
Post a Comment