http://www.androidpub.com/?document_srl=878847
위 링크 참고했구요
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"> <com.slidingtest.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> </com.slidingtest.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();
}
});
}
}
런타임 에러는 아래와 같습니다
로그를 봐도 모르겠네요 ㅠㅠ
SlideButton class의 생성자쪽에 문제인듯 한데 ㅡㅡ; 정확히는 모르겠네요~ 확인해 보세요..
제가 예전에 답변 달았던 적이 있는데.. 링크 해 드릴께요..
http://www.androidpub.com/1425244#comment_1425420




안녕하세요.
일단 보기에는, SlideButton.java 의 패키지명과 [slide_button.xml]에서 참조하는 SlideButton의 패키지명이 다르네요.