I can't understand what I'm doing wrong with my table which is made programmatically. My button is responsible for showing result in my cell. It works fine (correctly centered) the first time I click it. But when I click it again, the result moves to the left of cell (no longer centered). What should I do to fix it ?
public int x;
...
TableRow.LayoutParams rp = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT);
TableRow.LayoutParams ip = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT);
TableLayout wt = (TableLayout) v.findViewById(R.id.tl1);
TableRow row1 = new TableRow(getActivity().getApplicationContext());
row1.setLayoutParams(rp);
final TextView c = new TextView(getActivity().getApplicationContext());
c.setBackgroundResource(R.drawable.borders);
c.setTextColor(Color.BLACK);
c.setGravity(Gravity.CENTER);
c.setLayoutParams(ip);
row1.addView(c);
wt.addView(row1);
a1 = (Button) v.findViewById(R.id.a);
a1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(x == 1) {
c.setText("a");
} else {
c.setText("b");
}
}
});