Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set ImageViews in an external class so modifying them will change all Views that contain them?
    primarykey
    data
    text
    <p>So right now I have a main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/com.b" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background_color" android:textColorPrimaryInverse="#E97C03" &gt; &lt;LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/background_color" android:textColorPrimaryInverse="#E97C03" &gt; &lt;ImageView android:id="@+id/header_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/logo" android:layout_gravity="left" android:background="@color/seperator_bg_color" /&gt; &lt;ImageView android:id="@+id/build_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_camera" android:layout_gravity="left" /&gt; &lt;ImageView android:id="@+id/saved_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_details" /&gt; &lt;ImageView android:id="@+id/settings_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_menu_upload" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:id="@+id/seperator_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="1dip" android:background="@color/seperator_bg_color" android:textColor="@color/seperator_text_color" android:textStyle="bold" android:text="@string/header_build" android:textColorPrimaryInverse="#E97C03" /&gt; &lt;!-- &lt;TextView --&gt; &lt;!-- android:id="@+id/selection" --&gt; &lt;!-- android:layout_width="fill_parent" --&gt; &lt;!-- android:layout_height="wrap_content" --&gt; &lt;!-- /&gt;--&gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawSelectorOnTop="false" android:textColorPrimaryInverse="#E97C03" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Now, of course everything that uses the main.xml will have a header at the top(everything that is contained in the second, horizontal, LinearLayout.</p> <p>In all of those views however, I have links with header_image, saved_image, build_image, etc that will take the user to a specific view. The problem is that if I make a change, I have to go and edit every single Activity that has those links.</p> <p>Is there a way I can create an external class that will just contain information like this:</p> <pre><code>build =(ImageView)findViewById(R.id.build_image); build.setOnClickListener(buildClick); saved =(ImageView)findViewById(R.id.saved_image); saved.setOnClickListener(savedClick); prefs =(ImageView)findViewById(R.id.settings_image); prefs.setOnClickListener(prefsClick); </code></pre> <p>instead of having that code in every single Activity?</p> <p>EDIT: Essentially, I want to re-use my main.xml as my header for all activities, however where I set setOnClickListener I dont want to have to set those in every activity because if I change/add to the header, I have to dig through all the activities and change those.</p> <p>So I want to take the code above and put it in a separate class. That way, in an activity, I call that class, and it will set those values for the header. Or set onClick settings in the XML, if that is possible.</p>
    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. 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