2011-02-12 6 views
0

위젯에 대한 구성 화면을 추가하려고했는데 제대로 작동하지 않는 문제가 있습니다. 위젯을 처음으로 내 홈 화면에 추가하면 구성 화면이 잘 나타나지만 사용자가 위젯을 클릭 할 때 위젯이 나타나기 시작합니다. 그것이 작동하지 않는 부분입니다. 다음은 위젯 레이아웃 (widget.xml)에 대한 XML의Android 위젯이 작동하지 않음

Intent intent = new Intent(context, WidgetConfiguration.class);    
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);    
views.setOnClickPendingIntent(R.id.temperatureWidget, pendingIntent); 

:

는 여기의 onUpdate 코드의

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/frame" 
android:clickable="true" 
android:focusable="true" 
android:id="@+id/temperatureWidget"> 
<ImageView 
    android:layout_marginTop="15px" 
    android:layout_marginLeft="25px" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/img_thermometer"/> 
<TextView 
    android:id="@+id/TextView01" 
    android:layout_marginTop="35px" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="12pt" 
    android:textColor="@color/black" 
    android:text=" Temp: "/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="35px" 
    android:textSize="12pt" 
    android:textColor="@color/black" 
    android:id="@+id/txtTemperature"/> 

</LinearLayout> 

내가 위젯을 클릭

는 아무 일도 발생하지 않습니다. 어떤 아이디어?

+0

리모트 뷰 RemoteViews 전망 = 새로운 리모트 뷰 RemoteViews (context.getPackageName(), R.layout.widget); 게시 한 XML에 정의 된 R.layout.widget이 표시되지 않습니다. 두 개의 다른 XML을 언급하지 않았습니까? – hanspeide

+0

내가 게시 한 XML은 widget.xml이라는 레이아웃 파일입니다. –

답변

1

당신은 appwidget 문서에 주어진 라인을 추가 할 필요가

appWidgetManager.updateAppWidget(appWidgetId, views); 
+0

그게 전부 였어. 감사. 나는 몇 시간 동안 예제 문서를 꼼짝 않고보고 싶다. –

+0

답변 인 경우 답변으로 확인하십시오! – Gangnus

+0

정확히 이것을 코드에 삽입합니까? –

0

위젯의 XML 레이아웃에 뭔가 있다고 느낍니다. R.id.temperatureWidget을 클릭 할 수 있는지 확인해주십시오. 그 버튼입니까, 아니면 실제로 레이아웃 이름이 붙여진 것입니까?

+0

예, 클릭 가능합니다. 위젯의 LinearLayout입니다. 나는 lay 코드도 추가 할 것이다. –

관련 문제