Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging view based on integer from previous activity
    text
    copied!<p>I'm trying to get a view to change on an activity based on which view the user drags in the previous activity, but something is ill in my code and it refuses to work.</p> <p>The integer is stored as a public static int _id, and the integer is set for each view like so:</p> <pre><code>RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(150, 50); layoutParams.leftMargin = 250; layoutParams.topMargin = 250; layoutParams.bottomMargin = -250; layoutParams.rightMargin = -250; _view.setLayoutParams(layoutParams); _view.setOnTouchListener(this); _view.setId(1); </code></pre> <p>The integer is then sent to the next activity through this snippet of code.</p> <pre><code> case MotionEvent.ACTION_UP: _id = view.getId(); Intent intent = new Intent(MainActivity.this, Exit_Activity.class); intent.putExtra("smiley", _id); startActivity(intent); </code></pre> <p>And then it should theoretically be recieved in the next activity and define what view is visible at the top of the screen.</p> <pre><code>public class Exit_Activity extends Activity { ImageView _view; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_exit_); getActionBar().setDisplayHomeAsUpEnabled(true); Intent Intent = getIntent(); int intValue = Intent.getIntExtra("smiley", 0); ImageView img = new ImageView(this); img.setImageResource(R.drawable.smile); if (intValue == 1) {img.setImageResource(R.drawable.smile);} else if (intValue == 2) {img.setImageResource(R.drawable.frown);} } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_exit_, menu); return true; } </code></pre> <p>Right now it doesnt seem to do anything regardless of what view is dragged. Any input would be appreciated.</p> <p>EDIT:</p> <p>for bonus brownie points, I'm trying to do the same for text, it looks a little like this:</p> <pre><code> TextView textView = (TextView) findViewById(R.id.DynRes); setContentView(R.id.DynRes); if (intValue == 1) {DynRes.setText("Good to hear! have a nice day!");} else if (intValue == 2) {DynRes.appendText("We're very sorry, we'll try harder next time!");} </code></pre> <p>}</p> <p>I'm getting an error in eclipse that says "DynRes cannot be resolved" and it isn't entirely clear to me why. Thanks again.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload