【问题标题】:Problems setting the content description to image button将内容描述设置为图像按钮时出现问题
【发布时间】:2012-07-14 17:25:45
【问题描述】:

您好,我正在尝试为我的按钮购买设置内容描述,当我尝试访问它时,返回给我的值为 null。

这是按钮的代码。

//This is the button of the payment.
ImageButton make_pay = new ImageButton(this);
make_pay.setBackgroundResource(R.drawable.add_product);
makePay.addView(make_pay);
makePay.setContentDescription("Precio");

这是我用来访问的代码:

make_pay.setOnClickListener(new View.OnClickListener() {                                        

        @Override
        public void onClick(View makepay) {
            LinearLayout wrap_area = (LinearLayout)findViewById(R.id.division2);
            TextView test = new TextView(FrontActivity.this);
            wrap_area.addView(test);
            if (makepay.getContentDescription() == null){
                    test.setText("Precio:1");
            }else{
                    test.setText(makepay.getContentDescription().toString());
            }
        });
}

【问题讨论】:

    标签: android android-widget android-view


    【解决方案1】:

    您正在将内容描述设置为 makePay 对象(不管它是什么,可能是一个 ViewGroup)。但是,您将侦听器设置为 make_pay ImageButton,这是侦听器参数接收到的那个。因此,它的内容描述不是分配给另一个对象的描述。

    尝试改变这个:

    makePay.setContentDescription("Precio");
    

    用这个:

    make_pay.setContentDescription("Precio");
    

    无论如何,尽量不要以类似的方式命名您的对象。这可能会导致很大的混乱。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多