【问题标题】:android-getting error (No package identifier when getting value for resource number 0x0000000a)android-getting 错误(获取资源号 0x0000000a 的值时没有包标识符)
【发布时间】:2017-07-19 03:24:05
【问题描述】:

我正在使用 listView 和自定义 arrayadaptor(其中包含 3 个文本视图和一个整数值),而我正在使用 setText 设置文本并调用返回整数的方法。我正在链接自定义数组适配器和 word 文件,谢谢。

只有在使用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 ;
        }
        }

自定义适配器

    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;
        }

    }

【问题讨论】:

    标签: java android


    【解决方案1】:

    要使用setText方法返回整数值,需要使用setText(xxx+"");

    示例

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

    【讨论】:

    • 我必须在我的意思是在 + 之后放置什么
    • ""够了。
    【解决方案2】:

    使用这个:

    Integer.toString(currentPosition.getmPrice());
    

    或者这个:

    String.valueOf(currentPosition.getmPrice());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多