0
public void changePicture(final int champion, final String health,
        final String mana, final String armor, final String res,
        final String damage, final String ap, final String speed) {
    this.finish();

    final RelativeLayout test = (RelativeLayout) findViewById(R.id.layoutChamps);
    test.removeAllViews();

    final RelativeLayout layoutCreate = (RelativeLayout) findViewById(R.id.layoutCreate);
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View createView = layoutInflater.inflate(R.layout.create_build_page, null);
    test.addView(createView);
    ImageButton champ = (ImageButton) createView.findViewById(R.id.ibChamp);
    ImageButton items1 = (ImageButton) createView.findViewById(R.id.ibItem1);

    TextView tvItemMana = (TextView) findViewById(R.id.tvItemMana);

    tvItemMana.setTextColor(Color.YELLOW);

    champ.setImageResource(champion);
}

What this does is open another layout, but closes it after applying all the text and image changes on the opened layout, and not how I would like it do, which is close it then apply all the changes.

Piofmc
  • 365
  • 2
  • 4
  • 19
  • What happens when you step through the code line by line? – admdrew Mar 19 '14 at 23:22
  • @admdrew I've added a 5 second timer to see if that would change anything, but what it does is just wait 5 seconds before applying changes and closing the layout with the changes applied. – Piofmc Mar 19 '14 at 23:24
  • 3
    possible duplicate of [about finish() in android](http://stackoverflow.com/questions/2590947/about-finish-in-android). Also, even if you *did* exit at `this.finish()` and the View code wasn't executed, how would you then initialize the views for an Activity that doesn't exist? – A--C Mar 19 '14 at 23:27
  • @A--C Well, I have a base layout opened already and not closed, so when the extra layout is opened, it is on top of the previous layout. When the finish() is ran, it closes the extra layout, exposing the base layout, and runs all the changes needed for the layout. – Piofmc Mar 19 '14 at 23:38
  • 2
    @Piofmc All `View` operations you do inside an Activity pertain *only* to that Activity, and Activities have their *own* copy of a layout. It seems your code modifies an Activity's layout then immediately finishes that same Activity. This results in the Views you just configured to be destroyed. – A--C Mar 19 '14 at 23:47
  • @A--C So would that mean it tells the program to run finish() after everything is ran under the finish() line? – Piofmc Mar 19 '14 at 23:53
  • @Piofmc In a way, yes. Although refer to the question I linked because it is a much more clear statement. – A--C Mar 19 '14 at 23:58
  • Are you calling hte method in you onCreate? – Robin Dijkhof Mar 19 '14 at 23:59

0 Answers0