2012-07-31 2 views
0

레이아웃을 부풀려는 중이지만 작동하지 않습니다. Listview에서 Basedapater를 사용하고 있습니다.android에서 기본 어댑터를 사용할 때 Inflater가 작동하지 않습니다.

int can1 = Integer.parseInt(c.getString(c.getColumnIndex("InCan"))); 
if (can1 < 1) { 
    // ... 
} else { 
    View view; 
    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    view = inflater.inflate(R.layout.receipt, null); 
    TextView textView = (TextView) view.findViewById(R.id.rcan); 
    textView.setVisibility(View.GONE); 
    TextView coke3 = (TextView) view.findViewById(R.id.rcoke); 
    coke3.setVisibility(View.GONE); 

can[i] = " Coke In Can: "+c.getString(c.getColumnIndex("InCan")); 
} 

문제점을 지적 할 수 있습니까?

내 목록보기에 사용한 어댑터 클래스는 다음과 같습니다. 당신이 나를 도와주기를 바랍니다.

public class receiptadapter extends BaseAdapter { 
private Context context; 
private final String[] productname; 
private final String[] fixins; 
private final String[] original; 
private final String[] hot; 
private final String[] quantity; 
private final String[] price; 
private final String[] total; 
private final String[] salad; 
private final String[] coleslaw; 
private final String[] potato; 
private final String[] coke; 
private final String[] ccoke; 
private final String[] water; 
private final String[] can; 

public receiptadapter(Context context, String[] productname, String[] fixins, 
     String[] original, String[] hot, String[] quantity,String[] price, 
     String[] total, String[] salad, String[] coleslaw, String[] potato, 
     String[] coke, String[] ccoke, String[] water, String[] can){ 

    this.context= context; 
    this.productname = productname; 
    this.fixins = fixins; 
    this.original = original; 
    this.hot = hot; 
    this.quantity = quantity; 
    this.price = price; 
    this.total = total; 
    this.salad = salad; 
    this.coleslaw = coleslaw; 
    this.potato = potato; 
    this.coke = coke; 
    this.ccoke = ccoke; 
    this.water = water; 
    this.can = can; 
} 
public View getView(int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    LayoutInflater inflater = (LayoutInflater) context 
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    viewHolder holder = new viewHolder(); 

    if(convertView == null){ 
     convertView = inflater.inflate(R.layout.receipt, null); 

     holder.pname = (TextView) convertView.findViewById(R.id.rpname); 
     holder.fix = (TextView) convertView.findViewById(R.id.rfixins); 
     holder.orig = (TextView) convertView.findViewById(R.id.rorig); 
     holder.hot1 = (TextView) convertView.findViewById(R.id.rhot); 
     holder.qty = (TextView) convertView.findViewById(R.id.rquantity); 
     holder.price1 = (TextView) convertView.findViewById(R.id.rprice); 
     holder.sub = (TextView) convertView.findViewById(R.id.rsub); 
     holder.sal = (TextView) convertView.findViewById(R.id.rsal); 
     holder.col = (TextView) convertView.findViewById(R.id.rcol); 
     holder.pot = (TextView) convertView.findViewById(R.id.rpot); 
     holder.coke1 = (TextView) convertView.findViewById(R.id.rcoke); 
     holder.coke2 = (TextView) convertView.findViewById(R.id.rccoke); 
     holder.water1 = (TextView) convertView.findViewById(R.id.rwater); 
     holder.can1 = (TextView) convertView.findViewById(R.id.rcan); 
     convertView.setTag(holder); 


    }else{ 
     holder = (viewHolder) convertView.getTag(); 
    } 

    holder.pname.setText(productname[position]); 
    holder.fix.setText(fixins[position]); 
    holder.orig.setText(original[position]); 
    holder.hot1.setText(hot[position]); 
    holder.qty.setText(" Quantity: "+quantity[position]); 
    holder.price1.setText(" Price: PHP "+price[position]); 
    holder.sub.setText(" Sub - Total: PHP "+total[position]); 
    holder.sal.setText(salad[position]); 
    holder.col.setText(coleslaw[position]); 
    holder.pot.setText(potato[position]); 
    holder.coke1.setText(coke[position]); 
    holder.coke2.setText(ccoke[position]); 
    holder.water1.setText(water[position]); 
    holder.can1.setText(can[position]); 

    return convertView; 
} 

public int getCount() { 
    // TODO Auto-generated method stub 
    return productname.length; 
} 

public Object getItem(int arg0) { 
    // TODO Auto-generated method stub 
    return null; 
} 

public long getItemId(int position) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

class viewHolder{ 
    TextView pname; 
    TextView fix; 
    TextView orig; 
    TextView hot1; 
    TextView price1; 
    TextView qty; 
    TextView sub; 
    TextView sal; 
    TextView col; 
    TextView pot; 
    TextView coke1; 
    TextView coke2; 
    TextView water1; 
    TextView can1; 
} 

}

+2

오류가 발생 했습니까? 어떻게 일하지 않는거야? – 0gravity

+0

그것의 텍스트보기가 여전히 – User

답변

0

LayoutInflater inflater = null; 
inflater= (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE); 
view = inflater.inflate(R.layout.other, null); 
0

사용하는 대신 코드의 코드를 아래 코드를 사용해보십시오.

public class receiptadapter extends BaseAdapter { 
    private Context context; 
    private final String[] productname; 
    private final String[] fixins; 
    private final String[] original; 
    private final String[] hot; 
    private final String[] quantity; 
    private final String[] price; 
    private final String[] total; 
    private final String[] salad; 
    private final String[] coleslaw; 
    private final String[] potato; 
    private final String[] coke; 
    private final String[] ccoke; 
    private final String[] water; 
    private final String[] can; 
    private LayoutInflater mLinflater; 

    public receiptadapter(Context context, String[] productname, 
     String[] fixins, String[] original, String[] hot, 
     String[] quantity, String[] price, String[] total, String[] salad, 
     String[] coleslaw, String[] potato, String[] coke, String[] ccoke, 
     String[] water, String[] can) { 

     this.context = context; 
     this.productname = productname; 
     this.fixins = fixins; 
     this.original = original; 
     this.hot = hot; 
     this.quantity = quantity; 
     this.price = price; 
     this.total = total; 
     this.salad = salad; 
     this.coleslaw = coleslaw; 
     this.potato = potato; 
     this.coke = coke; 
     this.ccoke = ccoke; 
     this.water = water; 
     this.can = can; 
     this.mLinflater = LayoutInflater.from(context); 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 

     viewHolder holder = new viewHolder(); 

     if (convertView == null) { 
      convertView = mLinflater.inflate(R.layout.receipt, null); 
      holder.pname = (TextView) convertView.findViewById(R.id.rpname); 
      holder.fix = (TextView) convertView.findViewById(R.id.rfixins); 
      holder.orig = (TextView) convertView.findViewById(R.id.rorig); 
      holder.hot1 = (TextView) convertView.findViewById(R.id.rhot); 
      holder.qty = (TextView) convertView.findViewById(R.id.rquantity); 
      holder.price1 = (TextView) convertView.findViewById(R.id.rprice); 
      holder.sub = (TextView) convertView.findViewById(R.id.rsub); 
      holder.sal = (TextView) convertView.findViewById(R.id.rsal); 
      holder.col = (TextView) convertView.findViewById(R.id.rcol); 
      holder.pot = (TextView) convertView.findViewById(R.id.rpot); 
      holder.coke1 = (TextView) convertView.findViewById(R.id.rcoke); 
      holder.coke2 = (TextView) convertView.findViewById(R.id.rccoke); 
      holder.water1 = (TextView) convertView.findViewById(R.id.rwater); 
      holder.can1 = (TextView) convertView.findViewById(R.id.rcan); 
      convertView.setTag(holder); 
     } else { 
      holder = (viewHolder) convertView.getTag(); 
     } 

     holder.pname.setText(productname[position]); 
     holder.fix.setText(fixins[position]); 
     holder.orig.setText(original[position]); 
     holder.hot1.setText(hot[position]); 
     holder.qty.setText(" Quantity: " + quantity[position]); 
     holder.price1.setText(" Price: PHP " + price[position]); 
     holder.sub.setText(" Sub - Total: PHP " + total[position]); 
     holder.sal.setText(salad[position]); 
     holder.col.setText(coleslaw[position]); 
     holder.pot.setText(potato[position]); 
     holder.coke1.setText(coke[position]); 
     holder.coke2.setText(ccoke[position]); 
     holder.water1.setText(water[position]); 
     holder.can1.setText(can[position]); 

     return convertView; 
    } 

    public int getCount() { 
     // TODO Auto-generated method stub 
     return productname.length; 
    } 

    public Object getItem(int arg0) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    class viewHolder { 
     TextView pname; 
     TextView fix; 
     TextView orig; 
     TextView hot1; 
     TextView price1; 
     TextView qty; 
     TextView sub; 
     TextView sal; 
     TextView col; 
     TextView pot; 
     TextView coke1; 
     TextView coke2; 
     TextView water1; 
     TextView can1; 
    } 
} 
+0

tnx 응답하지만 동일한 결과에 표시되는에서 작동하지 않습니다. 여전히 볼 수 있습니다. 어쩌면 내가 그것에 대한 어댑터를 사용하고 있기 때문에. 목록보기에 표시됩니다. – User

+0

Baseadapter 또는 다른 것을 사용하고 있습니까? –

+0

예 baseadapter를 사용하고 있습니다. 어쩌면 그것이 이유라고 생각하고 있어요 – User