Reputation: 51
I have a table row that I implement onclick event to display a dialog and once clicked it'll change its background color.
But after I close the popup I would like to reset its background color back to normal. I can't do this with the following silly code I copied from the web.
mPrefRemindBtn=(TableRow)rootView.findViewById(R.id.pref_remind_btn);
Drawable orgin=mPrefRemindBtn.getBackground();
mPrefRemindBtn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
mPrefRemindBtn.setBackgroundColor(Color.argb(125, 155, 234, 135));
JOptionDialogEx dlg=new JOptionDialogEx(EventPreferenceActivity.this);
dlg.show();
}
});
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mPrefRemindBtn.setBackground(orgin);
Upvotes: 0
Views: 86
Reputation: 16537
The code is almost fine. Just add on Dismiss and on Cancel events and change the color from there. See: http://developer.android.com/reference/android/app/Dialog.html#setOnDismissListener(android.content.DialogInterface.OnDismissListener)
Upvotes: 1