无法使用 contentResolver
我几乎完成了我的应用程序...但现在我不能像这样使用 ContentResolver:
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(
getContentResolver(), imageUri); // Problem!!!!!
我不知道如何解决这个问题...如果我在我的主要活动中使用此语法,它就可以工作... 但它在我的类 CustomItemizedOverlay 中不起作用。
我标记了我必须修复的行...
eclipse 说:方法 getContentResolver () 对于 CustomItemizedOverlay 类型未定义
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import android.app.Dialog;
import android.app.AlertDialog;
import android.widget.TextView;
import android.view.View;
import android.widget.ImageView;
import android.view.LayoutInflater;
import android.widget.Toast;
import android.view.ViewGroup;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private String title;
private String id_string;
private String type;
private String name;
private String adress;
private String webpage;
private String opening_hours;
private Context context;
private Uri imageUri;
public CustomItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CustomItemizedOverlay(Drawable defaultMarker, Context context,String title,String id_string,String type,String name,String adress,String webpage,String opening_hours,Uri imageUri) {
this(defaultMarker);
this.context = context;
this.title = title;
this.id_string = id_string;
this.type = type;
this.name =name;
this.adress = adress;
this.webpage=webpage;
this.opening_hours = opening_hours;
this.imageUri = imageUri;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(title);
View layout = View.inflate(context, R.layout.dialog, null);
TextView id_text = (TextView)layout.findViewById(R.id.id);
id_text.setText("id:"+id_string);
TextView type_text = (TextView)layout.findViewById(R.id.type);
type_text.setText("type:"+type);
TextView name_text = (TextView)layout.findViewById(R.id.name);
name_text.setText("name:"+name);
TextView adress_text = (TextView)layout.findViewById(R.id.adress);
adress_text.setText("adress:"+adress);
TextView webpage_text = (TextView)layout.findViewById(R.id.webpage);
webpage_text.setText("webpage:"+webpage);
TextView opening_hours_text = (TextView)layout.findViewById(R.id.opening_hours);
opening_hours_text.setText("opening_hours:"+opening_hours);
ContentResolver con = new Contentresolver();
ImageView imageView = (ImageView) layout.findViewById(R.id.photo);
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(
getContentResolver(), imageUri); // Problem! HERE!!!!
imageView.setImageBitmap(imageBitmap);
dialog.setView(layout);
dialog.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}
I almost finished my appliaction ... but now I can't use the ContentResolver like this:
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(
getContentResolver(), imageUri); // Problem!!!!!
I have no idea how to fix this...it works if i use this syntax in my main-Activity...
but it doesnt't work in my class CustomItemizedOverlay.
I marked the line I have to fix ...
eclipse says: the methode getContentResolver () is undefined for the type CustomItemizedOverlay
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import android.app.Dialog;
import android.app.AlertDialog;
import android.widget.TextView;
import android.view.View;
import android.widget.ImageView;
import android.view.LayoutInflater;
import android.widget.Toast;
import android.view.ViewGroup;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private String title;
private String id_string;
private String type;
private String name;
private String adress;
private String webpage;
private String opening_hours;
private Context context;
private Uri imageUri;
public CustomItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CustomItemizedOverlay(Drawable defaultMarker, Context context,String title,String id_string,String type,String name,String adress,String webpage,String opening_hours,Uri imageUri) {
this(defaultMarker);
this.context = context;
this.title = title;
this.id_string = id_string;
this.type = type;
this.name =name;
this.adress = adress;
this.webpage=webpage;
this.opening_hours = opening_hours;
this.imageUri = imageUri;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(title);
View layout = View.inflate(context, R.layout.dialog, null);
TextView id_text = (TextView)layout.findViewById(R.id.id);
id_text.setText("id:"+id_string);
TextView type_text = (TextView)layout.findViewById(R.id.type);
type_text.setText("type:"+type);
TextView name_text = (TextView)layout.findViewById(R.id.name);
name_text.setText("name:"+name);
TextView adress_text = (TextView)layout.findViewById(R.id.adress);
adress_text.setText("adress:"+adress);
TextView webpage_text = (TextView)layout.findViewById(R.id.webpage);
webpage_text.setText("webpage:"+webpage);
TextView opening_hours_text = (TextView)layout.findViewById(R.id.opening_hours);
opening_hours_text.setText("opening_hours:"+opening_hours);
ContentResolver con = new Contentresolver();
ImageView imageView = (ImageView) layout.findViewById(R.id.photo);
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(
getContentResolver(), imageUri); // Problem! HERE!!!!
imageView.setImageBitmap(imageBitmap);
dialog.setView(layout);
dialog.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getContentResolver
是属于 Context 子类(例如 Activity)的方法。你的类没有这样的方法,所以你不能使用它。最简单的解决方法是在新类中存储对 Activity 的引用:然后在需要时调用
context.getContentResolver(...)
。getContentResolver
is a method that belongs to subclasses of Context, such as an Activity. your class does not have such a method so you can't use it. Easiest fix is to store a reference to your activity in your new class:and then call
context.getContentResolver(...)
when you need it.