원격 URL에서 이미지를 가져 와서 ImageView에 넣으려고합니다. ImageView 자체는 앱 위젯 내에 있으므로, 현재 이해하고있는 바로는 RemoteViews 내에 캡슐화되어 있으며 실제로 직접 처리되지는 않습니다.RemoteViews에서 ImageView를 업데이트하는 올바른 방법은 무엇입니까?
하지만 이미지를 표시하는 앱 위젯을 결코 얻을 수 없습니다. AsyncTask 확장을 사용하여 원격 URL에서 비트 맵으로 이미지를 가져 오는 중이며 이미지를 가져오고있는 것처럼 보입니다 (null이 아닌 비트 맵이 반환됩니다). 그래도 확인할 수는 없지만 .
저는 앱 위젯의 ImageView를 실제로 업데이트하는 데 잘못된 방법을 사용해야합니다.
레이아웃/new_app_widget.xml : NewAppWidget.java에서
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:contentDescription="@string/content" />
</RelativeLayout>
관련 비트 :
public class NewAppWidget extends AppWidgetProvider {
...
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
String strURL = "http://example.com/YqLOSfr4.png";
new ImageFetchAsyncTask(strURL, R.id.imageView).execute();
// ^^^^^
// in the above, I pass the URL and the id of the imageview, fetch
// the bitmap, and in the onPostExecute() method I use
// setImageViewBitmap(viewId, bitmap) to load the bitmap into the imageview
//
// I don't have the code to hand, but I can provide it. For now, someone
// may be able to tell me somewhere else I'm doing something wrong
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
의 AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mike.widgetapptest" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:debuggable="true"
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".NewAppWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/new_app_widget_info" />
</receiver>
</application>
</manifest>
여기
는 모든 관련 코드
당신은 백그라운드에서 자신의 라이프 사이클을 관리 할 타사 라이브러리를 사용해야합니다. 네트워크 이미지보기에 이미지 URL을 제공하면됩니다. –
Danial,이 글을 처음 접했기 때문에 조금이라도 의견을 넓힐 수 있다고 생각하십니까? 어떤 타사 라이브러리입니까? 이미지 URL을 네트워크 이미지보기에 제공하면 무엇을 의미합니까? – drmrbrewer
안드로이드에서 라이브러리 프로젝트를 사용하는 방법을 알고 계셨습니까? –