0

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");
            }
      }
});
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
zdc
  • 17
  • 3

1 Answers1

0

You call startActivity, pass an Intent into which you put the resources needed to indentify each image. Use the method putExtra to put the data you need tu pass on. Something like this:

Intent intent = new Intent(this,MyActivity.class);
intent.putExtra("url1",urlMyDomain+ "/image1.png");
intent.putExtra("path1",Environment.getExternalStorageDirectory()
                .getAbsolutePath()+"image1.png");
startActivity(intent);

In the onCreate method of the Activity you start, get the Intent and the extra info in it like this:

Intent intent = getIntent();
String url1 = intent.getStringExtra("url1");
String path1 = intent.getStringExtra("path1");
Gordak
  • 2,060
  • 22
  • 32
  • This code is in my fragment not activity. Secondly I'm planning make a big table that's why I made it programmaticaly not in xml and I'm worry that sending too much data by intent can make my program slow. But anyway, thx for sharing an idea. – zdc May 26 '15 at 17:15
  • Did you modify your post ? The answer is not related to it at all. – Gordak May 26 '15 at 17:27
  • It was modified by (moderator?), but sense of question has not changed. I was suprised your answer containing images but I thought, that is only overall example. – zdc May 26 '15 at 18:55
  • I think this answer was intended to another post. It doesn't make sense to me. – Gordak May 26 '15 at 19:03