Hi,
I need to add some of my buttons programmatically since the titles are
coming from a database that may change. The buttons are being add
fine, but are not clickable. I am using a custom background for the
buttons, but I am using the same background for some button I am using
from xml and they work find. If I add the line
countybutton[i].setFocusableInTouchMode(true); , the button can focus,
but doesn't click. I also tried to set it clickable, but it didn't
work. Here is my code:
res = getResources();
button_background = res.getDrawable(R.drawable.custom_button_gray);
context = getApplicationContext();
float scale = context.getResources().getDisplayMetrics().density;
for(int i = 0; i < county.size(); i++){
countybutton[i] = new Button(this);
countybutton[i].setText(county.elementAt(i));
countybutton[i].setBackgroundDrawable(button_background);
countybutton[i].setLayoutParams(new
LinearLayout.LayoutParams((int)
(85*scale),
LinearLayout.LayoutParams.FILL_PARENT));
countybutton[i].setTextColor(Color.WHITE);
countybutton[i].setTextSize(13 * scale);
countybutton[i].setOnClickListener(listener);
county_linear.addView(countybutton[i]);
}
listener = new OnClickListener(){
@Override
public void onClick(View v) {
Log.d(TAG, "a button was clicked");
}
};
any suggestions?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en