Hello people,
so I have my custom BaseAdapter that returns values from array. I
modified it in a way that when array is empty it will show string
"Empty list..." instead of showing nothing. This thing works but the
problem comes when I wanted to add an item to the list, I had trouble
with refreshing my ListView but after several tries and digging on the
net I found I have to call notifyDataSetChanged() or
notifyDataSetInvalidated(). I places the call to this function(s) in
onWindowFocusChanged(...) function in my Activity that is showing the
ListView.
The problem I have now is that I can not get the first added item to
show? I know that this is probably due to an error in my logic, since
on the first place I write "Empty list..." but I can not find the
error since I check if array is empty and if it is not then I set the
first ListView item to be the name of the first item in the array. I
am not that familiar with convertView and other things in my custom
BaseAdapter class so if anyone can help, thanks.
Second problem I have is that when I add several items, these items,
apart from the first item, do show in the list. So if the array
consists of the following items (111, 222, 333, 444, 555) my ListView
will show (Empty list..., 222, 333, 444, 555) but when I press MENU
button then the ListView shows this (555, 444, 333, 222, Empty
list...). It reverses itself??? Have no idea why that would happen?
Below is the code of my custom BaseAdapter class:
____________________________CODE_______________________________
public class MyCustBaseAdapterGroups extends BaseAdapter {
private static ArrayList<Group> groupListArray;
private static String mIntentData;
private LayoutInflater mInflater;
private static final String TAG = "MYLOG-TIMERZ";
private Group tmpGroup;
public MyCustBaseAdapterGroups(Context context, ArrayList<Group>
groupsList) {
// TODO Auto-generated constructor stub
groupListArray = groupsList;
try {
mInflater = LayoutInflater.from(context);
} catch (Exception e) {
Log.e(TAG, "Error:", e);
}
}
@Override
public int getCount() {
// TODO Auto-generated method stub
if (groupListArray != null) {
if (groupListArray.size() == 0) {
return 1;
} else {
return groupListArray.size();
}
} else {
return 0;
}
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
//return null;
if (position > 0) {
return groupListArray.get(position);
} else {
return 1;
}
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
if (position == 0) {
return 1;
} else {
return position;
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item,
null);
holder = new ViewHolder();
holder.txtName =
(TextView)convertView.findViewById(R.id.listItem);
convertView.setTag(holder);
Log.i(TAG,"convertViw=null");
} else {
holder = (ViewHolder)convertView.getTag();
}
if (groupListArray.size() == 0) {
holder.txtName.setText("Empty list...");
} else {
holder.txtName.setText(groupListArray.get(position).getName());
}
return convertView;
}
static class ViewHolder {
static TextView txtName;
}
}
_______________________END CODE______________________________
Thanks for the help!!!!
D.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en