[Solved]Problem with extending ImageView

Put your problem here if it does not fit any of the other categories.

[Solved]Problem with extending ImageView

Postby sasuke » Wed Jan 09, 2008 2:53 am

Hello, i want to create a component that extends an imageview (MyImageView) that change it's background when i clicked it , and back to the normal background if i don't click it.

There's an error when i run it : "android.view.viewinflate$InflateException:Binary XML file line #15: Error inflating class MyImageView"

Here's the code :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyImageView extends ImageView{    
  2.         public MyImageView(Context context,AttributeSet attr, Map inflateParams)
  3.         {
  4.                 super(context,attr,inflateParams);        
  5.         }
  6.        
  7.         public MyImageView(Context context)
  8.         {
  9.                 super(context);
  10.         }
  11.         @Override
  12.         protected void onDraw(Canvas arg0) {
  13.                 // TODO Auto-generated method stub
  14.                 super.onDraw(arg0);
  15.         }
  16.         @Override
  17.         public boolean onMotionEvent(MotionEvent event) {
  18.             int action = event.getAction();
  19.             boolean mCurDown = action == MotionEvent.ACTION_DOWN;          
  20.             boolean mCurUp = action == MotionEvent.ACTION_UP;
  21.             if (mCurDown) {            
  22.                 this.setImageDrawable(getResources().getDrawable(R.drawable.down));
  23.             } else
  24.             if (mCurUp) {
  25.                 this.setImageDrawable(getResources().getDrawable(R.drawable.up));
  26.             }
  27.             return true;
  28.         }
  29. }
  30.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.         android:layout_width="300px" android:layout_height="300px"
  5.         android:padding="0px" android:background="@drawable/bg">
  6.         <TableRow>
  7.                 <TextView android:text="PlayerColor"
  8.                         android:layout_width="100px" />
  9.                 <Button id="@+id/button" android:text="aasdasd"
  10.                         android:layout_width="wrap_content"
  11.                         android:layout_height="wrap_content" />
  12.         </TableRow>
  13.         <TableRow>
  14.                 <MyImageView
  15.                     id="@+id/imgv"
  16.                         android:layout_width="183px"
  17.                         android:layout_height="67px"
  18.                         android:src="@drawable/up"                     
  19.                         />
  20.         </TableRow>
  21. </TableLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



Where's the problem ?

Thank you :D
Last edited by sasuke on Wed Jan 09, 2008 3:36 am, edited 1 time in total.
sasuke
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Fri Nov 30, 2007 1:25 pm

Top

Postby sasuke » Wed Jan 09, 2008 3:34 am

Solved.. :lol:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <dj.android.testes.MyImageView
  3.  
  4. id="@+id/imgv"
  5.  
  6. android:layout_width="183px"
  7.  
  8. android:layout_height="67px"
  9.  
  10. android:src="@drawable/up"                     
  11.  
  12. />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
sasuke
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Fri Nov 30, 2007 1:25 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests