i have a listview with different components (2 linear layouts and a button) , what i want to do is when i click on a button that's inside one of those linear layouts , i want to access a textview that's inside the other linearlayout , is it possible ?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/listV2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/icon"
android:layout_width="85dp"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="150dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/nom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/textCname"
android:textSize="21dp"
android:textStyle="bold" />
<TextView
android:id="#+id/numero"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#color/textCother"
android:textStyle="italic" />
<TextView
android:id="#+id/ville"
android:layout_width="match_parent"
android:textColor="#color/textCother"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textStyle="italic" />
</LinearLayout>
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:visibility="invisible" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
>
<ImageView
android:id="#+id/remove"
android:onClick="contactRemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/edit"
android:onClick="contactEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"/>
<ImageView
android:onClick="contactCall"
android:id="#+id/call"
android:layout_marginLeft="22dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
what i want to do is access the value of android:id="#+id/numero"
when i click on one of the image views
You can set OnClickListener interface provided by View class. Something like this.
Implement listener on your activity class
public class SpinnerActivity extends AppCompatActivity implements
View.OnClickListener
Declare class level variables for your views
private TextView tvNumero;
private ImageView ivRemove, ivEdit, ivContactCall;
Find initialise value in onCreate() method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gildi_spinner);
tvNumero = (TextView) findViewById(R.id.numero)
ivRemove = (ImageView) findViewById(R.id.remove);
ivEdit = (ImageView) findViewById(R.id.edit);
ivContactCall = (ImageView) findViewById(R.id.contactCall);
ivRemove.setOnClickListener(this);
ivEdit.setOnClickListener(this);
ivContactCall.setOnClickListener(this);
}
Implemented class from Onclickistener, where you get on click event for your registered views
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.remove:
case R.id.edit:
case R.id.contactCall:
Toast.makeText(this, tvNumero.getText().toString(), Toast.LENGTH_SHORT).show();
break;
}
}
NOTE : tvNumero.getText().toString() gives you the value of your desired TextView.
UPDATE :
Firstly replace your ListView with RecyclerView
Refer RecyclerView Example tutorial.
Secondly to achieve onClick for your listed items
Refer recyclerview-onclick tutorial.
Pass context when you create your adapter, Use that context to get the inflated view.
Adapter adapter = new Adapter(this);
Then in Adpater Class constructor :
public Adapter(Context context){
context.findViewById(R.id.textview);//consider this as numero textview
}
Then access it as per your requirement. Hope it helps!
Related
Hello i'm stcuk by a little problem,
I want to add a new CardView with same set of the first CardView underneath the first Cardview only when i click on my button and this action can be repetable endlessly.
Because i'm beginner in android and i have litterally no idea how to make that.
If anyone can Copy Past this code and help me i will be very happy.
I know the spinner is void but its for after i just want to duplicate this.
my activity :
package com.example.lif.test;
public class testActivity extends AppCompatActivity {
Spinner idSpinnerLance;
EditText idEdtTempsLance;
TextView idTextViewPuissance, textViewTitre;
Button idButtonAdd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
idSpinnerLance = findViewById(R.id.idSpinnerLance);
idEdtTempsLance = findViewById(R.id.idEdtTempsLance);
textViewTitre = findViewById(R.id.textViewTitre);
idTextViewPuissance = findViewById(R.id.idTextViewPuissance);
idButtonAdd = findViewById(R.id.idButtonAdd);
idButtonAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
}
}
and my xml code :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".test.testActivity">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="10dp"
android:layout_margin="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ajouter une lance :"
android:textColor="?android:textColorPrimary"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/idSpinnerLance"
android:layout_width="150dp"
android:layout_height="47dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Temps :"
android:textColor="?android:textColorPrimary"
android:textSize="15dp"
android:textStyle="bold" />
<EditText
android:id="#+id/idEdtTempsLance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<Button
android:id="#+id/idButtonAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="add" />
</LinearLayout>
</ScrollView>
thank you
If those CardView will contain different data you can use a RecyclerView and on button click you can add an item in the list and notify the adapter this will add a new item(here item is your CardView created in a different XML file) on screen.
This could be helpful
and this too
EDITED
The examples in google searches and the android documentation are basic, and my question is more complex.
What I do not know, is how to put multiple components together and turn it into a single component. CardView + LinearLayout + TextView + ImageView = Custom View.
If I have a basic example, of cardview with at least one button and a space for external content. It would be enough for me to figure out how to do the rest. This within the cardview extension class, because I also do not know how the extension will understand where to create the components
EDITED 2
Example
QUESTION
I was trying to create a method of using Cardview with an expandable button, and I was able to do this in XML. But I wanted to be able to create a library so I could reuse it in other cases.
I'll show you the source code of what I did.
Layout XML
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/cwlltitulobtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#### TITLE OF BUTTON ####"
android:textSize="18sp"
android:textStyle="bold"/>
<ImageView
android:id="#+id/imgarrowdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:scaleType="fitEnd"
android:visibility="visible"
app:srcCompat="#drawable/ic_keyboard_arrow_down_black_24dp" />
<ImageView
android:id="#+id/imgarrowup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:scaleType="fitEnd"
android:visibility="gone"
app:srcCompat="#drawable/ic_keyboard_arrow_up_black_24dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/cwllconteudo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:visibility="gone">
<!-- ########################################
######## CARDVIEW CONTENT HERE #########
########################################-->
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Java code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.cwlltitulobtn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CVOpenCloseBTN();
}
});
}
public void CVOpenCloseBTN(){
ImageView arrowdown = (ImageView) findViewById(R.id.cvimgarrowdown);
ImageView arrowup = (ImageView) findViewById(R.id.cvimgarrowup);
LinearLayout pagecontent = (LinearLayout) findViewById(R.id.cwllconteudo);
if (conteudopage .getVisibility() == View.GONE) {
// it's collapsed - expand it
pagecontent.setVisibility(View.VISIBLE);
arrowdown.setVisibility(View.GONE);
arrowup.setVisibility(View.VISIBLE);
} else {
// it's expanded - collapse it
pagecontent.setVisibility(View.GONE);
arrowdown.setVisibility(View.VISIBLE);
arrowup.setVisibility(View.GONE);
}
}
}
My idea is that I can transform all this part of the xml and java code to be used in this way and faster, than to have to always repeat again:
<br.com.samantabiblioteca.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:titulo="#### TITLE OF BUTTON ####">
<!-- ########################################
######### CARDVIEW CONTENT HERE ########
########################################-->
</br.com.samantabiblioteca.CardView>
Is it possible to do this?
I have an OnClickListener that listens to Button A clicks. I also have 2 TextViews below the Button.
I want that on every click on Button A, the 2 TextViews will switch their places between them, like this:
Before clicking:
TextView A
TextView B
After clicking:
TextView B
TextView A
How can I do it? Is there a special function that meant to do that? or some kind of a trick? Thanks!
actvity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="start"
tools:context="com.intap.tof.MainActivity">
<TextView
android:id="#+id/txtA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp"
android:visibility="visible"/>
<TextView
android:id="#+id/txtB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtA
android:layout_marginTop="83dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="visible"
android:textSize="20dp" />
</RelativeLayout>
MainActivity.java:
txtA = (TextView) findViewById(R.id.txtA);
txtB = (TextView) findViewById(R.id.txtB);
float mAX = txtA.getX();
float mAY = txtA.getY();
float mBX = txtB.getX();
float mBY= txtB.getY();
txtA.setX(mBX);
txtA.setY(mBY);
txtB.setX(mAX);
txtB.setY(mAY);
Trick is changing the x and y axis of both views :
Your xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="start"
tools:context="com.intap.tof.MainActivity">
<TextView
android:id="#+id/txtA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp"
android:text="A"
android:tag="A"
android:clickable="true"
android:visibility="visible"/>
<TextView
android:id="#+id/txtB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtA"
android:text="B"
android:tag="B"
android:clickable="true"
android:layout_marginTop="83dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="visible"
android:textSize="20dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="switch"
android:id="#+id/btn1"
android:onClick="onClickButton"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Java Code :
public class MainActivity extends Activity {
TextView txtA,txtB;
boolean _isOnTxtA;
Button btn1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtA = (TextView)findViewById(R.id.txtA);
txtB = (TextView)findViewById(R.id.txtB);
btn1 = (Button)findViewById(R.id.btn1);
}
public void onClickButton(View v)
{
float mPos1x,mPos1y,mPos2x,mPos2y;
mPos1x = txtB.getX();
mPos1y = txtB.getY();
mPos2x = txtA.getX();
mPos2y= txtA.getY();
if(_isOnTxtA)
{
txtB.setX(mPos2x);
txtB.setY(mPos2y);
txtA.setX(mPos1x);
txtA.setY(mPos1y);
_isOnTxtA = false;
}
else
{
txtB.setX(mPos2x);
txtB.setY(mPos2y);
txtA.setX(mPos1x);
txtA.setY(mPos1y);
_isOnTxtA= true;
}
}
}
View.bringToFront method may be useful.
Where your layout is like:
<LinearLayout>
<TextView A>
<TextView B>
</LinearLayout>
To call bringToFront on TextView A will bring it front (the last position in the parent LinearLayout).
<LinearLayout>
<TextView B>
<TextView A>
</LinearLayout>
For more detailed example, below is layout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/text_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/text_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_a" />
<TextView
android:id="#+id/text_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_b" />
</LinearLayout>
In your OnClickListener (in your Activity) call:
View textViewA = findViewById(R.id.text_a);
textViewA.bringToFront();
This should work.
Toggling behavior can be achieved by this application. For example:
ViewGroup textHolder = (ViewGroup) findViewById(R.id.text_holder);
textHolder.getChildAt(0).bringToFront();
ViewGroup.getChildAt(0) always returns the first child of the ViewGroup. So everytime you call bringToFront on the first child will be bring to front.
All previous answers do not work because you use a relative layout where a linear layout will suffice.
If you have to go RelativeLayout, do the following in your click listener
TextView textA = (TextView) findViewById(R.id.txtA);
TextView textB = (TextView) findViewById(R.id.txtB);
RelativeLayout.LayoutParams textALayoutParams = (RelativeLayout.LayoutParams) textA.getLayoutParams();
textALayoutParams.addRule(RelativeLayout.BELOW, R.id.txtB);
textA.setLayoutParams(textALayoutParams);
RelativeLayout.LayoutParams textBLayoutParams = (RelativeLayout.LayoutParams) textB.getLayoutParams();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textBLayoutParams.removeRule(RelativeLayout.BELOW);
} else {
textBLayoutParams.addRule(RelativeLayout.BELOW,0);
}
textB.setLayoutParams(textBLayoutParams);
This will place A under B. You can do the same for reversing.
I have a ViewPager for the user to swipe between two layouts. My Activity's layout is the one containing the viewPager and I have two additional xml the ones that describe the layout of the screens that are to be swiped. My question is how can I implement the listeners of the buttons of these two layouts in my activity, the one containing the the viewPager. I'll also post the code I've written so far:
main:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/fonto1" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/grammi" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginEnd="17dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/aristerovelos2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aristerovelos3"
android:layout_marginTop="21dp" />
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
</android.support.v4.view.ViewPager>
</LinearLayout>
<ImageView
android:id="#+id/deksivelos1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/deksivelos3" />
</RelativeLayout>
first layout to be swiped in the viewPager
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_horizontal" >
<ImageView
android:id="#+id/galika"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="#drawable/gallika" />
<ImageView
android:id="#+id/germanika"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/germanika" />
<ImageView
android:id="#+id/ellinika"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/ellinika" />
<ImageView
android:id="#+id/agglika"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/agglika" />
The second is something like that, won't need posting it.
This is how I've tried setting my listeners but it won't work.
final LayoutInflater factory = getLayoutInflater();
final View panel = factory.inflate(R.layout.first_panel, null);
iv = (ImageView) panel.findViewById(R.id.el);
and then I set its listener which is trivial though it won't work properly
Ok I'm really sorry, I was really absent-minded I re-inflated another layout, not the one that was on the ViewPager that's why i was getting the button events I will post my way of making it work, just in case
#Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) container.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.first_panel;
break;
case 1:
resId = R.layout.second_panel;
break;
}
View view = inflater.inflate(resId, null);
((ViewPager) container).addView(view, 0);
if(resId==R.layout.first_panel)
ibellinika = (ImageView) view.findViewById(R.id.ellinika);
ibellinika.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(false);
progressBar.setMessage("Transfering Data ...");
}
});
return view;
}
I found many many threads and answers on how to make a Relative layout respond to click event. I've implemented my layout according to them. But still OnClickListener is not called. I have also given selector for it and it works well.
my_list_item xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/air.com.jingit.mobile"
android:layout_width="match_parent" android:layout_height="#dimen/actionBarHeight"
android:clickable="true"
android:background="#drawable/my_list_selector">
<com.loopj.android.image.SmartImageView
android:layout_width="#dimen/actionBarHeight"
android:layout_height="#dimen/actionBarHeight"
android:id="#+id/image"
android:scaleType="fitCenter"
android:layout_marginLeft="20dp"
android:clickable="false"
android:focusable="false"/>
<com.uma.mobile.view.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Loading..."
android:id="#+id/userName"
app:typeface="fonts/HelveticaNeue"
app:customStyle="Regular"
android:textSize="20sp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/image"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#000"
android:clickable="false"
android:focusable="false"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#aaa"
android:layout_alignBottom="#+id/image"></FrameLayout>
and this is where I inflate the view:
public MyListItem(final Context context, final Integer retailerId) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.my_list_item, this);
image = (SmartImageView) view.findViewById(R.id.image);
userName = (CustomTextView) view.findViewById(R.id.userName);
setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.i("INSIDE LIST","CLICK");
}
});
}
Edit 1:
This Relative layout is added to a linear layout which is inside a scrollview, so that it works like a list view. Does this has something to do???
list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:background="#eee">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/listContainer" />
</ScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_centerHorizontal="true"
android:src="#drawable/up_indicator"
android:layout_alignBottom="#+id/scrollView" />
Once i had a RelativeLayout not firing onClick event and it was because i had a Button in the middle of it, and the Button's onClick event was being fired, instead of the RelativeLayout one. Solved it implementing a listener for both of them:
OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
//Handle onClick
}
};
relativeLayout.setOnClickListener(listener);
button.setOnClickListener(listener);
Hope it helps!
Add OnClickListener in your RelativeLayout java Class