How to set backgroound drawable, when clicking a dyanamic created button like this :
I am using above code to create dyanamic button and track click of specific button :
for (int i = 1; i<8; i++) {
if(i==7)
{
btn = custom.myButton(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT), null, i+30, "...");
btn.setTag(i);
linear_paging.addView(btn);
}
else
{
btn = custom.myButton(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT), null, i+30, ""+i);
btn.setTag(i);
linear_paging.addView(btn);
}
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(Earned_New.this, v.getTag()+" clicked", Toast.LENGTH_SHORT).show();
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.black_rounded_background));
}
});
}
.
stackoverflow.comm
No comments:
Post a Comment