i've created an android application which creates 50 button dynamically,which works perfectly, but the problem is when i press one button which is defined statically which results in changing the button (text named as 5) background color to yellow.
can anyone please tell me some solution for this
my code is as given below
my Android Platform is 2.3.3
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
public class MyMain extends Activity {
Button change;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
change= (Button) findViewById(R.id.change);
setContentView(R.layout.mymain);
createCalender();
change.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// what to write here in order to change the color of button titled as 5 to yellow as its background color
}
});
}
public void createCalender()
{
LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1.0f);
param.setMargins(10, 10, 10, 10);
LinearLayout rowLayout=null;
Button[][] buttons = new Button[10][5];
int count=51;
int tab=1;
for (int i = 0; i<10; i++)
{
if(count%5==1)
{
rowLayout = new LinearLayout(this);
rowLayout.setBackgroundColor(Color.BLACK);
rowLayout.setWeightSum(5);
layoutVertical.addView(rowLayout,param);
count=count-5;
}
for(int j=0;j<5;j++)
{
buttons[i][j]=new Button(this);
buttons[i][j].setText(""+tab);
buttons[i][j].setHeight(55);
buttons[i][j].setWidth(80);
buttons[i][j].setTextColor(Color.BLACK);
buttons[i][j].setBackgroundColor(Color.GREEN);
tab++;
rowLayout.addView(buttons[i][j],param);
}
}
}
}