Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>EDIT:</p> <p>You have a basic misunderstanding about how to set the content view of your Activity and what finding a view by id means. </p> <ol> <li>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 <code>public static final class layout</code> and <code>public static final class id</code>. 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.</li> <li>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 <em>object</em> 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, <code>TextView tv = (TextView)findViewById(R.id.my_textview)</code> 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 <code>beDynRes.setText("Good to hear! have a nice day!")</code></li> <li>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. </li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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