How to use setEmptyView() with custom list layout in ListFragment - java

I'm using a paginator with a few Fragments.
I want to show a message when there are no entries in the list (Fragment).
I tried to use Textview with android:id="#id/android:empty but it doesn't work.
Custom list layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/padding_medium" >
<TextView
android:id="#+id/label_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/padding_medium"
android:text="#string/label_value"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/label_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/padding_medium"
android:text="#string/title_time"
android:textColor="#android:color/white"
android:textSize="16sp" />
</RelativeLayout>
List adapter class:
public class JournalAdapter extends ArrayAdapter<String> {
private final Context context;
private final List<String> values;
private final List<String> dates;
public JournalAdapter(Context context, List<String> values,
List<String> dates) {
super(context, R.layout.layout_journal_list, values);
this.context = context;
this.values = values;
this.dates = dates;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.layout_journal_list, parent, false);
TextView value = (TextView) rowView.findViewById(R.id.label_glucose);
TextView date = (TextView) rowView.findViewById(R.id.label_date);
value.setText(values.get(position));
date.setText(dates.get(position));
return rowView;
}
}
List parsing method:
private void initListView() {
values = dataSource.getAllValues();
List<String> values = new ArrayList<String>();
List<String> dates = new ArrayList<String>();
for (Value value : values) {
values.add(Double.toString(value.getValue()));
dates.add(secondsToDate(value.getDate()));
}
setListAdapter(new JournalAdapter(context, values, dates));
listView = getListView();
listView.setEmptyView(noItems("NO ITEMS"));
listView.setOnItemClickListener(this);
}
noItems method:
private TextView noItems(String text) {
TextView emptyView = new TextView(context);
emptyView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
emptyView.setText(text);
emptyView.setTextColor(Color.WHITE);
emptyView.setTextSize(20);
emptyView.setVisibility(View.GONE);
emptyView.setGravity(Gravity.CENTER_VERTICAL
| Gravity.CENTER_HORIZONTAL);
return emptyView;
}

This worked for me (got the solution from this question asked by William Remacle). What you might have missed is adding the created TextView to the ListView layout parent (second line of code from the bottom of the noItems method below):
In my ListFragment I used the following method to get a view for the empty view:
private TextView noItems(String text) {
TextView emptyView = new TextView(getActivity());
//Make sure you import android.widget.LinearLayout.LayoutParams;
emptyView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
//Instead of passing resource id here I passed resolved color
//That is, getResources().getColor((R.color.gray_dark))
emptyView.setTextColor(getResources().getColor(R.color.gray_dark));
emptyView.setText(text);
emptyView.setTextSize(12);
emptyView.setVisibility(View.GONE);
emptyView.setGravity(Gravity.CENTER_VERTICAL
| Gravity.CENTER_HORIZONTAL);
//Add the view to the list view. This might be what you are missing
((ViewGroup) getListView().getParent()).addView(emptyView);
return emptyView;
}
Then in the onStart() method of the the ListFragment set the the empty view:
#Override
public void onStart() {
super.onStart();
getListView().setEmptyView(
noItems(getResources().getString(R.string.widget_empty)));
}

android:id="#android:id/empty"
and not
android:id="#id/android:empty"

Related

can we set custom adapter to android fragment(My requirement Strictly needs only custom Adapter not array Adapter)

Iam trying display some data from web services in a Fragment,for this i need to use custom adapter because i am using pojo class to set and get data.
iam new to android and i know custom adapter to activity but i need for fragment.
My requirement is to display like the single item xml file singleitem.xml
<TextView
android:layout_width="match_parent"
android:id="#+id/txt1"
android:textSize="30sp"
android:gravity="center"
android:text="ine"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:id="#+id/txt2"
android:textSize="30sp"
android:gravity="center"
android:text="ine"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:id="#+id/txt3"
android:textSize="30sp"
android:gravity="center"
android:text="ine"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:id="#+id/txt4"
android:textSize="30sp"
android:gravity="center"
android:text="ine"
android:layout_height="wrap_content" />
which i want to display some data which contains 4 different fields in a listview row.
And i want custom adapter to setAdpater() to my Listview.
Is there any procedure to add custom adapter to Fragment or with in array adapter can i assign the values by using pojo class.Suggest me.
this is the custom adapter class iam using in Activity
can anyone suggest the possible changes for the adapter class
public class EnrollmentAdapter extends BaseAdapter {
MainActivity activity;
ArrayList<EnrollmentData> data;
LayoutInflater inflater;
public EnrollmentAdapter(MainActivity activity,ArrayList<EnrollmentData> data)
{
inflater = LayoutInflater.from(activity);
this.data = data;
}
#Override
public int getCount() {
return data.size();
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflater.inflate(R.layout.layout_enrollmentsingleitem,null);
TextView tv1 = (TextView)view.findViewById(R.id.txt1);
TextView tv2 = (TextView)view.findViewById(R.id.txt2);
TextView tv3 = (TextView)view.findViewById(R.id.txt3);
TextView tv4 = (TextView)view.findViewById(R.id.txt4);
tv1.setText(data.get(i).getReg_num());
tv2.setText(data.get(i).getW_list_on());
tv3.setText(data.get(i).getW_list_priority());
tv4.setText(data.get(i).getElements_to_complete());
return view;
}
I can solve my above question by using array adapter also meet my requirements
public class CourseCompleteAdapter extends ArrayAdapter<CourseCompletedInnerData> {
private Context context;
int layout;
ArrayList<CourseCompletedInnerData> data;
public CourseCompleteAdapter(Context context, int layout, ArrayList<CourseCompletedInnerData> data) {
super(context, layout,data);
this.data = data;
this.layout = layout;
this.context =context;
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(layout, parent, false);
}
TextView tvScore = (TextView)convertView.findViewById(R.id.txtcoursesinnerscore);
TextView tvActionstatus = (TextView)convertView.findViewById(R.id.txtcoursesinneractionstatus);
tvScore.setText(data.get(position).getScore());
tvActionstatus.setText(data.get(position).getAction_status());
return convertView;
}
}

CustomList adapter not TextView and ImageView

I want a listview displaying what is in to arrays with a customlist however the listview becomes blank when I run the app. Neither the TextView or Image of the list_item.xml is showing.
Here is MainActivity.java
public class MainActivity extends Activity {
ListView list;
List<Integer> users = new ArrayList<Integer>();
List<String> imageId = new ArrayList<String>();
Integer[] userNames;
String[] imageUrls;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
users.add(50);
imageId.add("https://color.adobe.com/build2.0.0-buildNo/resource/img/kuler/color_wheel_730.png");
userNames = new Integer[users.size()];
userNames = users.toArray(userNames);
imageUrls = new String[imageId.size()];
imageUrls = imageId.toArray(imageUrls);
CustomList adapter = new
CustomList(MainActivity.this, userNames, imageUrls);
list=(ListView)findViewById(R.id.listView);
list.setAdapter(adapter);
}
}
And here is CustomList.java:
public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final Integer[] userNames;
private final String[] imageUrl;
static class ViewHolderItem {
TextView textViewItem;
}
public CustomList(Activity context,
Integer[] users, String[] imageUrl) {
super(context, R.layout.list_item);
this.context = context;
this.userNames = users;
this.imageUrl = imageUrl;
}
static class ViewHolder{
TextView userName;
ImageView image;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list_item, null, true);
ViewHolder holder;
if(convertView == null){
convertView = LayoutInflater.from(context).inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.userName = (TextView)convertView.findViewById(R.id.userName);
holder.image = (ImageView)convertView.findViewById(R.id.img);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.userName.setText(String.valueOf(userNames[position]));
Picasso.with(context).load(imageUrl[position]).resize(1000, 1000).centerInside().into(holder.image);
return convertView;
}
}
Here is list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/userName" android:padding="10dp"/>
<ImageView
android:id="#+id/img"
android:tag="#string/app_name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
/>
</TableLayout>
Simply add this line in your CustomList.class
#Override
public int getCount() {
return userNames.length;
}
Also, I noticed that there's no width and height in the TextView.

Android - Load string array values to custom list view adapter

I have created a custom list view adapter and items for the list view is stored at String.xml. When I run the app I only shows a blank activity.
Please help me to fix this issue.
This is my custom adapter java class.
public class UserAdapter extends ArrayAdapter<User> {
public UserAdapter(Context context, ArrayList<User> users, String[] number) {
super(context, 0, users);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
User user = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.listview_singlerow, parent, false);
}
TextView tvName = (TextView) convertView.findViewById(R.id.org_name);
TextView tvNum = (TextView) convertView.findViewById(R.id.cn_num);
// Populate the data into the template view using the data object
tvName.setText(user.company_name);
tvNum.setText(user.contact_num);
return convertView;
}}
List View model class.
public class User {
public String company_name;
public Integer contact_num;
public User(String company_name, Integer contact_num) {
this.company_name = company_name;
this.contact_num = contact_num;
}}
Main Activity class where I attach adapter to the view.
public class activity_one extends Activity {
String[] number;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
number = getResources().getStringArray(R.array.dummy_data);
ArrayList<User> arrayOfUsers = new ArrayList<User>();
UserAdapter adapter = new UserAdapter(this, arrayOfUsers,number);
ListView listView = (ListView) findViewById(R.id.listView2);
listView.setAdapter(adapter);
}}
Since i am not 100% sure on what you want to do, ill show you a piece of my code and you can deduce from that what you need.
My DrawerListAdapter is an custom ListView adapter, and every item on that list consists of 3 objects - a String name, String imageurl, String description.
public class DrawerListAdapter extends ArrayAdapter<String> {
private final static int settingsCount = 4; // can ignore this
private Activity context;
// Next 3 lines: All data required for this adapter
private static ArrayList<String> itemname = null;
private static ArrayList<String> imgid;
private static ArrayList<String> itemDescription;
public DrawerListAdapter(Activity context, ArrayList<String> itemname, ArrayList<String> itemDescription, ArrayList<String> imgid) {
// R.layout.drawer_list_item is a layout that represents ONE item
// (not 100% sure, but i think the super class inflates this view itemname.size() times)
super(context, R.layout.drawer_list_item, itemname);
this.context=context;
// saving the required data
DrawerListAdapter.itemDescription = itemDescription;
DrawerListAdapter.itemname=itemname;
DrawerListAdapter.imgid=imgid;
}
#Override
public View getView(int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.drawer_list_item, null,true);
// the views that are present in R.layout.drawer_list_item
TextView txtTitle = (TextView) rowView.findViewById(R.id.tvName);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
TextView extratxt = (TextView) rowView.findViewById(R.id.tvDescription);
txtTitle.setText(itemname.get(position));
extratxt.setText(itemDescription.get(position));
// setting the image here of the list item here
if (position < settingsCount) {
imageView.setImageResource(Integer.parseInt(imgid.get(position)));
} else {
Glide.with(context).load(imgid.get(position)).into(imageView);
}
return rowView;
};
// need to override the getCount. this function just returns the amount of items in your list
#Override
public int getCount(){
if (itemname != null)
return itemname.size();
return 0;
}
This is initialized by:
private void init() {
mDrawerList = (ListView) findViewById(R.id.left_drawer);
if (adapter == null) {
ArrayList<String> itemname = new ArrayList<String>();
itemname.add("item1");
itemname.add("item2");
itemname.add("item3");
itemname.add("item4");
ArrayList<String> imgid = new ArrayList<String>();
imgid.add(R.drawable.pic1 + "");
imgid.add(R.drawable.pic2 + "");
imgid.add(R.drawable.pic4 + "");
imgid.add(R.drawable.pic3 + "");
ArrayList<String> itemDescription = new ArrayList<String>();
itemDescription.add("desc1");
itemDescription.add("desc2");
itemDescription.add("desc3");
itemDescription.add("desc4");
adapter=new DrawerListAdapter(this, itemname, itemDescription, imgid);
setOnItemClickListener(); // sets onClick for each item on the list
}
mDrawerList.setAdapter(adapter);
}
and the drawer_list_item.xml just in case you are intrested:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp" />
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#429bd9" />
<TextView
android:id="#+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:maxLines="2"
android:textColor="#79e5a4" />
</LinearLayout>

View.gettag returning null, what have I missed in ListView/ArrayAdapter setup?

I have a custom class "Something" which holds some ints and strings. I'm making a page to allow the user to see each current Something's description, and a button to edit or delete next to each one.
I have overridden toString() in the Something class, so that it can return a description to be put into the TextView field.
list_task_edit.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".EditTaskList">
...
<ListView
android:id="#+id/edit_task_listview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
...
</LinearLayout>
edit_task_list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/edit_task_name"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/edit_task_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_edittask"
android:onClick=""
/>
<Button
android:id="#+id/edit_task_delete"
android:layout_width="wrap_content"
android:text="#string/button_delete_task"
android:layout_height="wrap_content"
android:onClick="deleteTask"
/>
</LinearLayout>
(I haven't put a method for editTask yet, as I'm not up to there)
public class EditTaskList extends Activity {
private static ArrayList<Something> list;
ArrayAdapter<Something> arrayAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_task_edit);
list = MainActivity.getMasterList();
arrayAdapter = new ArrayAdapter<Something>
(this,
R.layout.edit_task_list_item,
R.id.edit_task_name,
list);
ListView listView = (ListView)findViewById(R.id.edit_task_listview);
listView.setAdapter(arrayAdapter);
}
public void deleteTask(View view){
Something thisItem = (Something)view.getTag();
if(thisItem == null){
System.out.println("Bad things");
}
arrayAdapter.remove(thisItem);
arrayAdapter.notifyDataSetChanged();
}
...
}
My diagnostic line to check if thisItem == null is going off every time. What am I missing? Am I declaring the ArrayAdapter wrong somehow?
Updated, working code. In case it's useful to others:
public class EditTaskList extends Activity {
private static ArrayList<Something> list;
private CustomAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_task_edit);
ListView listView = (ListView)findViewById(R.id.edit_task_listview);
list = MainActivity.getMasterList();
adapter = new CustomAdapter(this, list);
listView.setAdapter(adapter);
}
public void resetAdapter(){
adapter.notifyDataSetChanged();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.edit_task_list, menu);
return true;
}
public class CustomAdapter extends ArrayAdapter<Something>{
private ArrayList<Something> things;
private LayoutInflater inflater;
class ViewHolder {
public TextView text;
public Button editButton;
public Button deleteButton;
}
public CustomAdapter(Context context, ArrayList<Something> things) {
super(context, R.layout.edit_task_list_item, things);
inflater = LayoutInflater.from(context);
this.things = things;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// reuse views
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = inflater.inflate(R.layout.edit_task_list_item, null);
// configure view holder
viewHolder.text = (TextView) convertView.findViewById(R.id.edit_task_name);
viewHolder.editButton = (Button) convertView.findViewById(R.id.edit_task_edit);
viewHolder.deleteButton = (Button) convertView.findViewById(R.id.edit_task_delete);
convertView.setTag(viewHolder);
}
else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.text.setTag(position);
viewHolder.text.setText(things.get(position).toString());
viewHolder.deleteButton.setTag(position);
viewHolder.editButton.setTag(position); //currently does nothing
viewHolder.deleteButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
int tag = (Integer)view.getTag();
things.remove(tag);
resetAdapter();
}
});
return convertView;
}
}
}
Your deleteTask event will not return your list item, instead it will return a button view.
To get the functionality which you want, you should build a custom adapter to keep track of your list items. To do this, you will need to extend the BaseAdapter.
See this response for more detail:
How to add/remove item from listview in android when click button in item listview
The key point is that in the GetView method, you are able to set a tag on your list button which denotes the position of the container item. This then will let you delete the item specified by that position in the OnClickListener for the button.

Toast when checked in custom adapter listview

I want when I checked on check box the code returns string of text view that's in the same row only.
I'm using LayoutInflater and another class which has code for creating list containing strings.
My code :
public class InteractiveArrayAdapter extends ArrayAdapter<model> {
private final List<model> list;
private final Activity context;
public InteractiveArrayAdapter(Activity context, List<model> list) {
super(context, R.layout.rep, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rep, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.TextView07);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.CheckBox05);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
model element = (model) viewHolder.checkbox
.getTag();
element.setSelected(buttonView.isChecked());
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
}
my xml :
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/h103"
android:layout_width="match_parent"
android:layout_height="27dp"
android:layout_x="0dp"
android:layout_y="0dp"
android:background="#drawable/back1" >
<TableRow
android:id="#+id/TableRow05"
android:layout_width="match_parent"
android:layout_height="27dp"
android:layout_marginTop="4dp" >
<CheckBox
android:id="#+id/CheckBox05"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="-4dp"
android:button="#drawable/test" />
<TextView
android:id="#+id/TextView07"
android:layout_width="220dp"
android:layout_height="22dp"
android:layout_marginLeft="23dp"
android:layout_marginTop="-6dp"
android:text="" />
<TextView
android:id="#+id/TextView08"
android:layout_width="110dp"
android:layout_height="22dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="-4dp"
android:text="095110263" />
</TableRow>
</TableLayout>
</AbsoluteLayout>
You have to work on checkbox.onclicklistener rather then checkbox.onCheckedChanged because if you uses it in list view then it will automatically called then your checked check box will hide out.
new OnClickListener()
{
#Override
public void onClick(View view)
{}
}
in onclicklistener, you get view as parameter which is a check box. here view has a method of getparent() which returns you a view in which your check box is set. you can check it by printing in log. if u got parent of check box then u can also get all child views of parent in which 1 child view is check box. from all child views u can get there values to show them in toast. if check box's parent has another parent in view of list item then u can also get parent of parent view by calling a getparent() method.
Please keep in mind that views have parent child relation so if you wants all child then you have to get parent.
First Add 1 button at bottom of ur list view btnOk
btnOk.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
StringBuffer responseText = new StringBuffer();
ArrayList<model> almodel = adapter.almodel;
responseText.append("The following were selected...\n");
for(int i=0;i<almodel.size();i++)
{
model m = almodel.get(i);
if(m.isSelected())
{
responseText.append("\n" + m.getName());
}
}
Toast.makeText(getApplicationContext(),responseText,Toast.LENGTH_LONG).show();

Categories

Resources