Reputation: 9373
I am trying to make it so the the last row and first row of my listview will have rounded edges. Right now I am just trying to get the first row to have rounded edges. I able to accomplish this but a few random rows usually the 5-7 and 15 or 16th rows will be set to the rounded edges background too and I can't figure out why.
Here is the part of my adapter code where I try to set the rounded edges drawable:
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.row, null);
holder = new ViewHolder();
holder.title = (TextView) vi.findViewById(R.id.title);
holder.desc = (TextView) vi.findViewById(R.id.details);
holder.date = (TextView) vi.findViewById(R.id.date);
holder.price = (TextView) vi.findViewById(R.id.price);
holder.location = (TextView) vi.findViewById(R.id.location);
holder.newImage = (ImageView) vi.findViewById(R.id.savedNewItemsRibbon);
holder.rellay = (RelativeLayout) vi.findViewById(R.id.widget30);
//holder.image = (ImageView) vi.findViewById(R.id.thumb);
vi.setTag(holder);
}else{
holder = (ViewHolder) vi.getTag();
}
if(position == 0 && firstRow){
holder.rellay.setBackgroundResource(R.drawable.roundededges);
firstRow = false;
}else{
//vi.setBackgroundColor(Color.WHITE);
}
Log.d("MySQL", "COunt:"+position);
holder.price.setText(data.get(position).getPrice());
holder.location.setText(data.get(position).getUrl());
datasource = new PostDataSource(activity);
datasource.open();
if(datasource.checkIfNew(data.get(position).getTitle())){
holder.newImage.setVisibility(View.VISIBLE);
//vi.setBackgroundColor(Color.YELLOW);
}else{
holder.title.setTextColor(Color.BLACK);
}
holder.title.setText(data.get(position).getTitle());
holder.desc.setText(data.get(position).getDescription());
holder.date.setText(data.get(position).getPubDate());
holder.location.setText(data.get(position).getCity());
//holder.title.setText(data.get(0).getTitle());
//imageLoader.DisplayImage((data.get(position).getThumbnail()), activity,holder.image, 72, 72);
URL url = null;
try {
url = new URL((data.get(position).getThumbnail()));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream content = null;
/*
try {
//content = (InputStream)url.getContent();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Drawable d = Drawable.createFromStream(content , "src");
Bitmap mIcon1 = null;
try {
mIcon1 =
BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
holder.image.setImageBitmap(Bitmap.createScaledBitmap(mIcon1, 72, 72, false));
*/
positionCount++;
return vi;
}
I've tried just using position==0 to set it to no avail. Any ideas?
Upvotes: 0
Views: 469
Reputation: 19153
This is most likely because the framework is passing a non-null convertView
into your getView
method, which happens to come from your first row.
The easiest fix is to unset the background resource for every row but the first:
if (position == 0){
holder.rellay.setBackgroundResource(R.drawable.roundededges);
} else {
holder.rellay.setBackgroundResource(0);
}
Upvotes: 2