Package Name : selva.list
Project Name : Cust_ListView
Version : 1.5 (Supports 1.5 and above versions)
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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
<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" />
</LinearLayout>
Cust_ListviewActivity.java
package selva.list;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Cust_ListviewActivity extends ListActivity {
String[] Fruits = {
"Apple",
"Banana",
"Orange",
"Mango",
"Grapes",
"Jack Fruit",
"Strawberry",
"cucumber",
"pumpkin"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
ListView lstView = getListView();
//lstView.setChoiceMode(0); //CHOICE_MODE_NONE
//lstView.setChoiceMode(1); //CHOICE_MODE_SINGLE
lstView.setChoiceMode(2); //CHOICE_MODE_MULTIPLE
lstView.setTextFilterEnabled(true);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked, Fruits));
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Cust_ListviewActivity extends ListActivity {
String[] Fruits = {
"Apple",
"Banana",
"Orange",
"Mango",
"Grapes",
"Jack Fruit",
"Strawberry",
"cucumber",
"pumpkin"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
ListView lstView = getListView();
//lstView.setChoiceMode(0); //CHOICE_MODE_NONE
//lstView.setChoiceMode(1); //CHOICE_MODE_SINGLE
lstView.setChoiceMode(2); //CHOICE_MODE_MULTIPLE
lstView.setTextFilterEnabled(true);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked, Fruits));
// note : You will get pop-up menu when type R . layout .
//Then select your option. It will display items with different customization
}
public void onListItemClick(ListView parent, View v, int position, long id)
{
parent.setItemChecked(position, parent.isItemChecked(position));
Toast.makeText(this,"You have selected " + Fruits[position],Toast.LENGTH_SHORT).show();
}
}
}
public void onListItemClick(ListView parent, View v, int position, long id)
{
parent.setItemChecked(position, parent.isItemChecked(position));
Toast.makeText(this,"You have selected " + Fruits[position],Toast.LENGTH_SHORT).show();
}
}
OUTPUT:
Click Here To Download Source Code
No comments:
Post a Comment