2017-07-19 20 views
0

我使用listView和自定義arrayadaptor(其中包含3個文本視圖和一個整數值),而我使用setText設置文本和調用方法返回整數。我正在鏈接自定義數組適配器和word文件,謝謝。android-getting錯誤(獲取資源編號0x0000000a的值時沒有包標識符)

我只在調用使用setText方法返回整數值的方法時出錯。

public class Word { 

     private static final int dollar = 10; 
     private static final String buttonNAME = "ADD TO CART"; 

     //@var price var used for price description 
     private int m Price; 
     //@var mItemName var used for displaying item 
     private String mItemName; 

     //@constructor used to assign dag to the var 

     public Word(int mPrice, String mItemName) 
     { 
      this.mPrice = mPrice; 
      this.mItemName = mItemName; 

     } 

     public int getmPrice() 
     { 
      return mPrice; 
     } 

     public String getmItemName(){ 
      return mItemName; 
     } 

     public int getdollar()throws Exception{ 
      return dollar ; 
      } 
     public String getButtonnName(){ 
      return buttonNAME ; 
     } 
     } 

customadapter

class WordAdapter extends ArrayAdapter<Word> { 



     WordAdapter(Activity context, ArrayList<Word> items){ 

      super(context,0,items); 
     } 

     @NonNull 
     @Override 
     public View getView(int position, View convertView, @NonNull ViewGroup parent) { 
      // Check if the existing view is being reused, otherwise inflate the view 
      View listItemView = convertView; 
      if(listItemView == null) { 
       listItemView = LayoutInflater.from(getContext()).inflate(
         list_items, parent, false); 
      } 

      // Get the {@link AndroidFlavor} object located at this position in the list 
      Word currentPosition= getItem(position); 

      // Find the TextView in the list_item.xml layout with the ID version_name 

      // Find the TextView in the list_item.xml layout with the ID version_number 
      TextView itemTextView = (TextView) listItemView.findViewById(R.id.listitems_item); 
      // Get the version number from the current AndroidFlavor object and 
      // set this text on the number TextView 


      if (currentPosition != null) { 
       itemTextView.setText(currentPosition.getmItemName()); 
      } 


      TextView dollarTextView = (TextView) listItemView.findViewById(R.id.listitems_dollor); 
      // Get the version number from the current AndroidFlavor object and 
      // set this text on the number TextView 

      try { 
       if (currentPosition != null) 
        dollarTextView.setText(currentPosition.getdollar()); 

      } 
      catch (Exception e) 
      { 
       e.getStackTrace(); 
       Log.v("coffe","satya"); 
      } 



      Button buttoName = (Button) listItemView.findViewById(R.id.listitems_addcart); 

      if (currentPosition != null) { 
       buttoName.setText(currentPosition.getButtonnName()); 
      } 
      TextView priceTextView = (TextView) listItemView.findViewById(R.id.list_items_price); 
      try { 
       if (currentPosition != null) 
        priceTextView.setText(currentPosition.getmPrice()); 

      } 
      catch (Exception e) 
      { 
       e.getStackTrace(); 
       Log.v("coffe","satya"); 
      } 


      return listItemView; 
     } 

    } 

回答

1

要使用setText方法返回整數的價值,你需要使用setText(xxx+"");

priceTextView.setText(currentPosition.getmPrice()+""); 
+0

什麼我必須在cottations地方,我意思是+ –

+0

已經足夠了。 –

+0

謝謝,爲我工作 –

相關問題