TextView에서 자체 컨트롤 확장을 만듭니다. 알림시 RemoteViews에서이 컨트롤을 사용해보십시오. 그러나 show notify를 시도하면 문제가 발생합니다.ClassNotFoundException RemoteViews
java.lang.ClassNotFoundException : {namespace}. {myClass}.
하지만 활동 레이아웃에 동일한 컨트롤을 추가하면 어떻게됩니까? 다 괜찮아. 무엇이 문제입니까?
내 텍스트 뷰 :
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/notification_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@drawable/ic_launcher" />
<TextView
android:id="@+id/notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/notification_image"
android:text="notification_title"
android:textStyle="bold" />
<{namespace}.ScrollingTextView
android:id="@+id/notification_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/notification_title"
android:layout_toRightOf="@+id/notification_image"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="notification_message" />
:
public class ScrollingTextView extends TextView {
public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollingTextView(Context context) {
super(context);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean focused) {
if (focused)
super.onWindowFocusChanged(focused);
}
@Override
public boolean isFocused() {
return true;
}
}
레이아웃에 통보 내
알림 전화 :
Intent intent = new Intent(context, NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(R.drawable.ic_launcher, tickerText, System.currentTimeMillis());
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
RemoteViews contentView = new RemoteViews(_context.getPackageName(), R.layout.notify);
contentView.setImageViewResource(R.id.notification_image, R.drawable.ic_launcher);
contentView.setTextViewText(R.id.notification_title, state.contentTitle);
contentView.setTextViewText(R.id.notification_message, state.contentText);
notification.contentView = contentView;
_notificationManager.notify(1, notification);
- UPDATE 2012년 5월 8일 17시 8분
안드로이드 매니페스트에서 나는 = "com.test"값 패키지가 있습니다.
{namespace}에서 나는 understoo com.test이고 {myClass} - ScrollingTextView입니다. com.test 패키지에 ScrollingTextView가 배치되었습니다.
오류가 발생했습니다 : android.view.InflateException : 이진 XML 파일 줄 # 25 : com.test.ScrollingTextView 클래스를 확장하는 동안 오류가 발생했습니다.
라인 (25)은 ScollingTextView를 선언 라인 인 경우 :
<com.test.ScrollingTextView ...
전체 오류 :
couldn't inflate view for notification com.test/0x1
android.view.InflateException: Binary XML file line #25: Error inflating class com.test.ScrollingTextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.widget.RemoteViews.apply(RemoteViews.java:1580)
at com.android.systemui.statusbar.tablet.TabletStatusBar.inflateViews(TabletStatusBar.java:1938)
at com.android.systemui.statusbar.tablet.TabletStatusBar.addNotificationViews(TabletStatusBar.java:1744)
at com.android.systemui.statusbar.tablet.TabletStatusBar.addNotification(TabletStatusBar.java:891)
at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:231)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.test.ScrollingTextView
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
... 16 more
코드를 게시하면 코드에 코딩 된 것을 상상할 수 없습니까? – Erol
첫 번째 소식을 업데이트하십시오. ContenView 설정을 비활성화하면 모두 작동합니다. –
{namespace}. {myClass} 인 클래스는 무엇입니까? 어떤 라인에 오류가 있습니까? – Erol