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();
Related
Items in the gridView sometimes overlap or move up or down a bit.But gets fixed when scrolling back up again.Unfortunately I can't provide an image because I am new here .I am not sure if i am doing something in code.But when use listView there is no problem.
Xml for the gridView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.gametalks.MainActivity"
android:background="#color/card_white">
<GridView
android:columnWidth="10dp"
android:numColumns="2"
android:id="#+id/listView"
android:dividerHeight="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:verticalSpacing="30dp"
></GridView>
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
Here is the adapter:
[public class GameAdapter extends ArrayAdapter<GameNews> {
public GameAdapter(#NonNull Context context, List<GameNews> gameNews ){
super(context, 0, gameNews);
if(gameNews == null)
{
return;
}
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
GameNews currentNews = getItem(position);
// Check if the existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.grid_item, parent, false);
final ViewHolder v = new ViewHolder();
// Find the TextView in the grid_item.xml layout with the ID version_name
v.Heading = (TextView) listItemView.findViewById(R.id.title);
v.description = (TextView) listItemView.findViewById(R.id.description);
v.newsImage = (ImageView) listItemView.findViewById(R.id.image) ;
v.source = (TextView) listItemView.findViewById(R.id.source);
v.time = (TextView) listItemView.findViewById(R.id.time);
v.menuButton = (Button) listItemView.findViewById(R.id.popup);
listItemView.setTag(v);
v.menuButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
PopupMenu popup = new PopupMenu(getContext(),view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popup_menu, popup.getMenu());
popup.show();
}
});
}
ViewHolder viewHolder = (ViewHolder) listItemView.getTag();
//Setting title to current news title
viewHolder.Heading.setText(currentNews.getTitle());
viewHolder.description.setText(currentNews.getDescription());
viewHolder.newsImage.setTag(currentNews.getphotoUrl());
viewHolder.source.setText(currentNews.getSource());
viewHolder.time.setText(currentNews.getTime());
// Picasso.with(getContext()).load(currentNews.getphotoUrl()).into(viewHolder.newsImage);
if (URLUtil.isValidUrl(currentNews.getphotoUrl())) {
Picasso.with(getContext())
.load(currentNews.getphotoUrl())
.resize(350,300)
.tag(tag)
.error(R.drawable.placeholder)
.placeholder(R.drawable.placeholder)
.into(viewHolder.newsImage);
} else {
Picasso.with(getContext())
.load(R.drawable.right_line)
.resize(350,300)
.tag(tag)
.noPlaceholder()
.into(viewHolder.newsImage);
}
return listItemView;
}
public static class ViewHolder {
TextView Heading;
TextView description;
ImageView newsImage;
TextView source;
TextView time;
Button menuButton;
}
}][1]
If you need any other details please ask.
This happened due to the reason that i set the size of gridView items to wrap content and hence different items had different sizes.This caused unstability in the gridView.I fixed it by giving the items of the gridView a fixed dp size.And now it has no problem
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;
}
}
I have made my custom adapter and am adapting an array of "persons". In my list item xml i have put a checkbox, but this is where i get confused. I want my list to only be able to have one check box checked at a time. And i also want to implement an OnCheckBox click listener of some sort to preform an action each time a different check box is selected.
this is my custom adapter
public class PersonAdapter extends BaseAdapter {
Context mContext;
Person[] mPersonArray;
public PersonAdapter(Context context , Person[] persons) {
mContext = context;
mPersonArray = persons;
}
#Override
public int getCount() {
return mPersonArray.length;
}
#Override
public Object getItem(int position) {
return mPersonArray[position];
}
#Override
public long getItemId(int position) {
return 0; // we wont use
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
// brand new
convertView = LayoutInflater.from(mContext).inflate(R.layout.person_list_item , null);
holder = new ViewHolder();
holder.nameText = (TextView) convertView.findViewById(R.id.nameTextView);
holder.birthDateText = (TextView) convertView.findViewById(R.id.birthDateTextView);
holder.checkBoxList = (CheckBox) convertView.findViewById(R.id.checkBox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Person personForList = mPersonArray[position];
holder.nameText.setText(personForList.getName());
holder.birthDateText.setText(personForList.getBirthDate());
return convertView;
}
public static class ViewHolder {
TextView nameText;
TextView birthDateText;
CheckBox checkBoxList;
}
Here is my list item xml
<RelativeLayout 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"
tools:background="#ff53">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Evan Dix"
android:id="#+id/nameTextView"
android:textColor="#ff323232"
android:textSize="30sp"
android:layout_marginLeft="50dp"
android:layout_marginStart="86dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="11-12-12"
android:id="#+id/birthDateTextView"
android:textColor="#ff323232"
android:layout_marginStart="23dp"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/imageView"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#android:drawable/presence_invisible"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/nameTextView"
android:layout_marginStart="12dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="29dp"
android:checked="false"
android:clickable="true"
android:choiceMode = "singleChoice"/>
And inside my class where i am populating the listview.... it extends ListAdapter
Person[] personArray = new Person[mPersonArrayList.size()];
personArray = mPersonArrayList.toArray(personArray);
PersonAdapter adapter = new PersonAdapter(this , personArray);
setListAdapter(adapter);
I had used this in my project and you can also try, but if you have to check one checkbox at one time then why are you using checkbox you have to use radiobutton.
// initialize selectPosition in your base adapter
int selectedPosition = -1;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
// brand new
convertView = LayoutInflater.from(mContext).inflate(R.layout.person_list_item , null);
holder = new ViewHolder();
holder.nameText = (TextView) convertView.findViewById(R.id.nameTextView);
holder.birthDateText = (TextView) convertView.findViewById(R.id.birthDateTextView);
holder.checkBoxList = (CheckBox) convertView.findViewById(R.id.checkBox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Person personForList = mPersonArray[position];
holder.nameText.setText(personForList.getName());
holder.birthDateText.setText(personForList.getBirthDate());
holder.checkBoxList.setChecked(position == selectedPosition);
holder.checkBoxList.setTag(position);
holder.checkBoxList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
selectedPosition = (Integer) view.getTag();
notifyDataSetInvalidated();
notifyDataSetChanged();
}
});
return convertView;
}
It sounds like what your are looking for is a radio button rather than a check box.
Check boxes are made so that you are able to select multiple items of one category, where radio buttons are made so that you are able to only click one of the category.
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.
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"