Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8794317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:14:06+00:00 2026-06-13T23:14:06+00:00

I’m trying to get a view to change on an activity based on which

  • 0

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.

The integer is stored as a public static int _id, and the integer is set for each view like so:

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);

The integer is then sent to the next activity through this snippet of code.

       case MotionEvent.ACTION_UP:  
        _id = view.getId();
        Intent intent = new Intent(MainActivity.this, Exit_Activity.class);
        intent.putExtra("smiley", _id);
        startActivity(intent);

And then it should theoretically be recieved in the next activity and define what view is visible at the top of the screen.

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;
}

Right now it doesnt seem to do anything regardless of what view is dragged. Any input would be appreciated.

EDIT:

for bonus brownie points, I’m trying to do the same for text, it looks a little like this:

    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!");}

}

I’m getting an error in eclipse that says “DynRes cannot be resolved” and it isn’t entirely clear to me why. Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:14:07+00:00Added an answer on June 13, 2026 at 11:14 pm

    The reason it does nothing is because you aren’t grabbing an existing ImageView and manipulating it (e.g. by findViewById()). Instead you’re just creating a new ImageView. You need to either grab an existing imageview or add that newly created one to to your contentview’s viewgroup.

    EDIT:

    You have a basic misunderstanding about how to set the content view of your Activity and what finding a view by id means.

    1. Each of your Activities has a main content view. You set this in onCreate by calling setContentView and passing in the id of one of your layouts (R.layout.somelayout). The integer id that you are passing in is simply a public static int located inside of an auto-generated class called R.java. Inside that class are multiple nested static classes, such as public static final class layout and public static final class id. The The Android Asset Packaging Tool (aapt) takes your application resource files (things defined in XML) and compiles them so you can reference them in code. So, there is no type or variable, etc with the name Dynres, for example. All there is, is a public int that you can references as R.id.Dynres. BUT, again, you can think of that int as a compiled representation of your xml resource. Which leads me to my next point.
    2. findViewById is a method that can search inside of some ViewGroup (viewgroup being some view that can hold other children, like a linearlayout or a relativelayout (as opposed to TextView and other widgets that do not contain children)) to find a child view with the id of the one you passed in. So, for example if you have reference to some View, you can call someView.findViewById(R.id.someId) which will try to find a view with that id anywhere in that view’s hierarchy. If there is no such view with that id inside of that view, then it returns null. Now, you can also call findViewById inside of an Activity, which simply searches inside of the layout that you set as the contentView of your Activity for that child view. So, for example, if you set the contentview of your Activity like setContentView(R.layout.mylayout) and mylayout.xml was some linearlayout that had a textview inside of it with the id of ‘my_textview’ then you can do findViewById(R.id.my_textview). Ok, great this finds the view, but now, to actually have a TextView object as in a Java object you can work with and call methods on as a TextView, you need to cast that View to a TextView. So, TextView tv = (TextView)findViewById(R.id.my_textview) simply uses the id to find that view then you cast it to an object of type TextView assigned to the variable “tv” so now tv is what you need to use to call methods on, etc. So, your code needs to beDynRes.setText("Good to hear! have a nice day!")
    3. You don’t want to set the contentview to be the textview. The contentview should be some ViewGroup defined in your xml layout that CONTAINS the textview.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I need to clean up various Word 'smart' characters in user input, including but
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.