0
votes

i am adding a footer having 2 imageviews to my app using include tag. I am able to view the footer and access the image view ids in source code but am not able to setOnclicklistener to these imageviews.

In main.xml i have

include layout="@layout/common_footer"

In common_footer.xml

?xml version="1.0" encoding="UTF-8"? LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="#228b22"

ImageView android:id="@+id/image1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" android:paddingRight="20px" android:clickable="false"

ImageView android:id="@+id/image2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/sample_0" android:clickable="false"

LinearLayout

In source code

View inflatedView = View.inflate(this, R.layout.common_footer, null); ImageView b = (ImageView)inflatedView.findViewById(R.id.image1); LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT ,LayoutParams.WRAP_CONTENT); b.setLayoutParams(lp); b.setClickable(false); b.setSelected(false); b.setOnClickListener(mClickListener); }

private OnClickListener mClickListener = new OnClickListener() 
{ 
        public void onClick(View v) 
        { 
            Intent i = new Intent(TableImageLayout.this, TableImageLayout2.class);
            startActivity(i);   
        } 
}; 

But my Onclicklistener is not working.

Please forward your valuable suggestions

Thanks in advance:)

1

1 Answers

0
votes

Hello i have solved the issue Earlier i was using viewgroup as null. View inflatedView = View.inflate(this, R.layout.common_footer, null);

the problem will be solved if we provide the view group as the parent layout. As my layout is table layout tb. View inflatedView = View.inflate(this, R.layout.common_footer, tb); works fine.