제가 Slide Button을 구현 하려고
http://www.androidpub.com/?document_srl=878847
그냥가자님의 게시물을 보고 따라했습니다.
그런데 XML에서 런타임 에러가 나네요 ㅠㅠ
에러 나는 부분 로그 캡쳐 해서 첨부파일로 올렸습니다..
코드는 아래와 같구요
slide_button.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <a.b.c.SlideButton android:layout_width="112px" android:layout_height="48px" android:content="@+id/slideContentLayout" android:handle="@+id/slideHandle" android:orientation="horizontal" android:id="@+id/slideButton" android:background="@drawable/btnback"> <Button android:id="@+id/slideBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/btn"/> <LinearLayout android:id="@+id/slideContentLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#000000"> </LinearLayout> </a.b.c.SlideButton> </LinearLayout>
SlideButton.java
package com.slidingtest; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.Checkable; import android.widget.SlidingDrawer; import android.widget.SlidingDrawer.OnDrawerCloseListener; import android.widget.SlidingDrawer.OnDrawerOpenListener;
public class SlideButton extends SlidingDrawer implements Checkable, OnDrawerOpenListener, OnDrawerCloseListener { int mButtonResource = 0; OnCheckChangedListner mOnCheckChangedListner; public SlideButton(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub setOnDrawerOpenListener(this); setOnDrawerCloseListener(this); } @Override public boolean isChecked() { // TODO Auto-generated method stub return !isOpened(); } @Override public void setChecked(boolean checked) { // TODO Auto-generated method stub if(!isOpened() != checked){ if(checked) { this.animateClose(); } else { this.animateOpen(); } } } @Override public void toggle() { // TODO Auto-generated method stub // super.toggle(); if(!isOpened()) { this.animateOpen(); } else { this.animateClose(); } } public interface OnCheckChangedListner { public void onCheckChanged(View v, boolean isChecked); }
@Override public void onDrawerOpened() { // TODO Auto-generated method stub if(mOnCheckChangedListner != null) { mOnCheckChangedListner.onCheckChanged(this, isChecked()); } } @Override public void onDrawerClosed() { // TODO Auto-generated method stub if(mOnCheckChangedListner != null) { mOnCheckChangedListner.onCheckChanged(this, isChecked()); } } public OnCheckChangedListner getOnCheckChangedListner() { return mOnCheckChangedListner; } public void setOnCheckChangedListener(OnCheckChangedListner onCheckChangedListner) { this.mOnCheckChangedListner = onCheckChangedListner; } }
MainActivity.java
package com.slidingtest;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
private SlideButton sb;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slide_button);
sb = (SlideButton)findViewById(R.id.slideButton);
sb.setOnCheckChangedListener(new SlideButton.OnCheckChangedListner() {
@Override
public void onCheckChanged(View v, boolean isChecked) {
// TODO Auto-generated method stub
Log.i("aaa", "bbb");
Context context = null;
Toast t = Toast.makeText(context, Boolean.toString(isChecked), Toast.LENGTH_LONG);
t.show();
}
});
}
}
뭐가 문제인건지 고수분들의 조언 부탁드립니다 ㅠㅠ
패키지 이름 맞춰서 쓰세요.... xml에 패키지 이름 틀렸네요.