Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>make a custom.xml</p> <pre><code> &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;ImageView android:id="@+id/thumbnail_view" android:src="@drawable/ic_launcher" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/message_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/thumbnail_view" android:textSize="18sp" android:text="MyText" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>then in main.xml , include this custom.xml</p> <pre><code> &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal"&gt; &lt;include android:id="@+id/customView" layout="@layout/custom"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is my mainActivity.class</p> <pre><code> package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.TextView; public class MainActivity extends Activity implements OnClickListener { private String TAG = MainActivity.class.getSimpleName(); ImageView img; ImageView img1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView txt = (TextView)findViewById(R.id.message_view); img = (ImageView) findViewById(R.id.thumbnail_view); img1 = (ImageView) findViewById(R.id.thumbnail_view1); img.setOnClickListener(this); img1.setOnClickListener(this); } @Override public void onClick(View v) { if(v== img){ // do something for img } else if (v== img1){ //do something for img1 } } } </code></pre>
 

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