Friday, April 26, 2013

[android help] How to set dyanamic generated textview's background on clicking


How to set backgroound drawable, when clicking a dyanamic created button like this :


enter image description here


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

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...