0

すみません、私はフランス人です^^

それで、私はあなたにちょっとした質問をしました!

listView に非表示ボタンを表示したいのですが、コードが (1 つだけではなく) すべてのボタンを表示している場合。

私のコードを見てください:

public class ListViewShoplistAdapter extends BaseAdapter {

private ArrayList<Product> listCategory;
private Activity activity;
private ShopList shoplist;

public ListViewShoplistAdapter(Activity activity,ArrayList<Product> listCategory, ShopList shoplist) {
    super();
    this.activity = activity;
    this.listCategory = listCategory;
    this.shoplist = shoplist;
}

public int getCount() {
    return listCategory.size();
}

public Product getItem(int position) {
    return listCategory.get(position);
}

public long getItemId(int position) {
    return position;
}

private class ViewHolder {
    public TextView productName;
    public TextView productPrice;
    public TextView productBrand;
    public ImageView product;
    public Button changeQuantity; 
    public RelativeLayout background;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder view;
    LayoutInflater inflator = activity.getLayoutInflater();

    if(convertView == null) {
        view = new ViewHolder();
        convertView = inflator.inflate(R.layout.listviewshoplist, parent, false);

        view.productName = (TextView) convertView.findViewById(R.id.name);
        view.productPrice = (TextView) convertView.findViewById(R.id.price);
        view.productBrand = (TextView) convertView.findViewById(R.id.brand);
        view.changeQuantity = (Button) convertView.findViewById(R.id.changequantity);
        view.background = (RelativeLayout) convertView.findViewById(R.id.relativeLayout1);
        view.product = (ImageView) convertView.findViewById(R.id.imgproduct);
        convertView.setTag(view);
    }else {
        view = (ViewHolder) convertView.getTag();
    }

    String productName = listCategory.get(position).getName();
    view.productName.setText(productName);

    if (position==0){ // JUST for the first position, display the changeQuantity button ! => Button is displayed for all rows...
        view.changeQuantity.setVisibility(View.VISIBLE);
    }

    String price = String.valueOf(listCategory.get(position).getPrice())+"€";
    view.productPrice.setText(price);

    return convertView;

}

}

ご協力ありがとうございました !

4

3 に答える 3

1

私の経験に基づいて、あなたは常にelse後ろに置く必要がありますif

だからあなたは次のようなものが必要です

if (position==0){ // JUST for the first position, display the changeQuantity button ! => Button is displayed for all rows...
        view.changeQuantity.setVisibility(View.VISIBLE);
    } else {
view.changeQuantity.setVisibility(View.INVISIBLE); // or View.GONE
}
于 2012-10-22T10:24:03.973 に答える
1

ボタンも設定する必要がありGONEます

 if (position==0){ 
    view.changeQuantity.setVisibility(View.VISIBLE);
 } else 
    view.changeQuantity.setVisibility(View.GONE);
于 2012-10-22T10:24:54.907 に答える
0

あなたのコードでこれを試してください..

if (position==0){ // JUST for the first position, display the changeQuantity button ! => Button is displayed for all rows...
    view.changeQuantity.setVisibility(View.VISIBLE);
}
else   // visibility gone
{
    view.changeQuantity.setVisibility(View.Gone);

}
于 2012-10-22T10:24:21.770 に答える