我以编程方式创建了图像按钮并设置了图像
img = new ImageView(this);
img.setBackgroundResource(R.drawable.starred);
img.setLayoutParams(new TableRow.LayoutParams(28,28));
我想在用户点击图片时更改图片
img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try
{
AlertDialog.Builder builder = new AlertDialog.Builder(Job_Description.this);
builder.setTitle("Save this Job ?");
// builder.setMessage("whould You like to save job");
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
img.setImageResource(R.drawable.starapplied);
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
dialog.cancel();
}
});
builder.show();
}catch(Exception e)
{
Log.d("Image clicked", e.toString());
}
}
});
我在这里做错了吗?