Note that there are some explanatory texts on larger screens.

plurals
  1. POImageButton Cannot be added into the Sliding Menu Drawer
    primarykey
    data
    text
    <blockquote> <p>I am doing a small program in that i have added one drawer which opens on button click, and in that i am able to display Text, Buttons but i want to add ImageButton in that drawer, then it will gives the error.</p> </blockquote> <pre><code>public class slidingDrawerDemo extends Activity implements OnClickListener { ImageButton slideButton, b1, b2; SlidingDrawer slidingDrawer; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); slideButton = (ImageButton) findViewById(R.id.slideButton); slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer); b1 = (ImageButton) findViewById(R.id.imageButton1); b2 = (ImageButton) findViewById(R.id.imageButton2); b1.setOnClickListener(this); b2.setOnClickListener(this); OnClickListener(this); slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() { @Override public void onDrawerOpened() { slideButton.setBackgroundResource(R.drawable.closearrow); } }); slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() { @Override public void onDrawerClosed() { slideButton.setBackgroundResource(R.drawable.openarrow); } }); } @Override public void onClick(View v) { Button b = (Button) v; Toast.makeText(slidingDrawerDemo.this, b.getText() + " Clicked", Toast.LENGTH_SHORT).show(); } </code></pre> <p>}</p> <p>activity_main.xml</p> <pre><code>activity_main.xml &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom" android:orientation="vertical" &gt; &lt;SlidingDrawer android:id="@+id/SlidingDrawer" android:layout_width="500dp" android:layout_height="fill_parent" android:background="@layout/border" android:content="@+id/contentLayout" android:handle="@+id/slideButton" android:orientation="vertical" android:padding="5dip" android:scrollbarStyle="insideInset" &gt; &lt;Button android:id="@+id/slideButton" android:layout_width="158dp" android:layout_height="100dp" android:background="@drawable/closearrow" &gt; &lt;/Button&gt; &lt;LinearLayout android:id="@+id/contentLayout" android:layout_width="fill_parent" android:layout_height="667dp" android:gravity="center" android:orientation="vertical" android:padding="5dip" &gt; &lt;ImageButton android:id="@+id/imageButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/imagesb" /&gt; &lt;ImageButton android:id="@+id/imageButton1" android:layout_width="405dp" android:layout_height="200dp" android:src="@drawable/imagesa" /&gt; &lt;/LinearLayout&gt; &lt;/SlidingDrawer&gt; &lt;/LinearLayout&gt; </code></pre> <p>and the error is, java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.ImageButton</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