0

リストビューの最後の行と最初の行の端が丸くなるようにしようとしています。現在、最初の行のエッジを丸くしようとしています。私はこれを達成することができますが、通常は5〜7行目と15行目または16行目のいくつかのランダムな行が丸みを帯びたエッジの背景にも設定され、その理由がわかりません。

これは、丸いエッジのドローアブルを設定しようとするアダプターコードの一部です。

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;

}

position==0 を使用して無駄に設定しようとしました。何か案は?

4

1 に答える 1

2

これは、フレームワークが null 以外をメソッドに渡しているためである可能性が高く、convertViewこれはgetViewたまたま最初の行からのものです。

最も簡単な修正は、最初の行を除くすべての行のバックグラウンド リソースを設定解除することです。

   if (position == 0){
       holder.rellay.setBackgroundResource(R.drawable.roundededges);
   } else {
       holder.rellay.setBackgroundResource(0);
   }
于 2012-12-20T03:40:32.900 に答える