【发布时间】:2017-01-18 08:24:05
【问题描述】:
Hlw,
问题1: 我正在开发一个应用程序,其中有一个类似 ImageView 的收藏按钮,我单击并更改此图像资源(已完成),但我想在用户再次单击此图像视图并且图像保持不变时设置操作。
问题2: 我有两个图像按钮“加号”和“减号”我设置了条件,当用户单击 + 按钮中间 textview 增加 1 时,当它达到 10 时,按钮将不可点击,对于减号按钮,当 textviw 等于 = 0 然后它不起作用... 我是按条件完成的,但是当减号按钮达到 0 并且在单击加号按钮后,它会增加但不会减少它仍然无法点击... 我怎么解决这个问题? Image like this
productWrapper.plus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(context, "Plus", Toast.LENGTH_SHORT).show();
try
{
String presentValStr= finalProductWrapper2.selectedQuantity.getText().toString();
int presentIntVal=Integer.parseInt(presentValStr);
presentIntVal++;
if (presentIntVal>=10){
Toast.makeText(context,"You can select max 10 product",Toast.LENGTH_LONG).show();
finalProductWrapper2.plus.setEnabled(false);
}
finalProductWrapper2.selectedQuantity.setText(String.valueOf(presentIntVal));
}
catch(Exception e)
{
e.printStackTrace();
Toast.makeText(context,"Error! please try again",Toast.LENGTH_LONG).show();
}
}
});
final ProductWrapper finalProductWrapper = productWrapper;
productWrapper.heart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finalProductWrapper.heart.setImageResource(R.drawable.heart2);
}
});
【问题讨论】:
标签: android android-layout onclicklistener imagebutton android-imagebutton