android 地图视图问题
在我的应用程序中,我使用地图视图,它显示我当前位置附近的地点。如果用户单击地图图钉,我将显示有关该地点的详细信息。为了显示详细信息,我使用了一些动画部分。
当用户单击隐藏动画时,我想再次显示以前的地图。为了显示动画,我已经设置了内容视图,当用户单击隐藏动画时,我再次从主活动中调用该函数(从创建时开始) )
所以当我调用该函数时,它在地图视图中给了我空指针异常。 请帮忙!!!
这是我的代码
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
// searchButton=(Button)findViewById(R.id.searchId);
// searchButton.setOnClickListener(this);
// nearestButton=(Button)findViewById(R.id.nearestId);
// nearestButton.setOnClickListener(this);
url1=ongetUrl();
new FetchTask(FindFishActivity.this, url1).execute(null);
}
private class FetchTask extends AsyncTask<Object,Object,Object>
{
ProgressDialog progressDialog;
Context ctx;
String str_url;
public FetchTask(Context mcontext,String str)
{
this.ctx=mcontext;
this.str_url=str;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=ProgressDialog.show(FindFishActivity.this,"Loading Data","Please wait...");
}
@Override
protected Object doInBackground(Object... params)
{
String res_str=onWebService(str_url);
parse(res_str);
return true;
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
onMapDisplay();
progressDialog.dismiss();
}
public void onMapDisplay() {
String lakeNameString;
setContentView(R.layout.mapview);
mapView=(MapView)findViewById(R.id.mapview);
// if(mapView==null)
// {
// MapView view=new MapView(FindFishActivity.this,"0pPZGIF27HwAISdkPQhUWYj12n5N63e-vAbun1g");
// setContentView(R.layout.mapview);
// }
mapView.setStreetView(true);
mapView.setSatellite(false);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(true);
mapOverlays=mapView.getOverlays();
drawable=FindFishActivity.this.getResources().getDrawable(R.drawable.pushpin4);
myOverlays=new MyOverlays(drawable,FindFishActivity.this);
for(int i=0;i<latitude.size();i++)
{
if(!latitude.get(i).equals(""))
{
lat=Double.parseDouble(latitude.get(i));
latitudearr.add(lat);
}
}
for(int i=0;i<longitude.size();i++)
{
if(!longitude.get(i).equals(""))
{
lon=Double.parseDouble(longitude.get(i));
longitudearr.add(lon);
}
}
for(int i=0;i<lakeNameList.size();i++)
{
if(!lakeNameList.get(i).equals(""))
{
lakeNameString=lakeNameList.get(i);
}
}
for(int k=0;k<latitudearr.size();k++)
{
startPoint=new GeoPoint((int)(latitudearr.get(k) * 1E6),(int)(longitudearr.get(k) * 1E6));
mapController.animateTo(startPoint);
overlayItem=new OverlayItem(startPoint, ""+lakeNameList.get(k).toString(),""+lDescription.toString());
myOverlays.addOverlay(overlayItem);
mapOverlays.add(myOverlays);
mapController.setZoom(6);
mapView.invalidate();
}
}
,用于显示动画部分
public void onShowInfo() {
setContentView(R.layout.tutorial5);
// LayoutInflater inflater=(LayoutInflater)FindFishActivity.this.getSystemService( Context.LAYOUT_INFLATER_SERVICE);
// View c=inflater.inflate(R.layout.tutorial5,(ViewGroup) findViewById(R.id.linearlayoutID));
transparentPanel=(TransparentPanel)findViewById(R.id.popup_window);
transparentPanel.setVisibility(View.VISIBLE);
transparentPanel.startAnimation(animShow);
final Button hideButton = (Button)findViewById(R.id.hide_popup_button);
hideButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
transparentPanel.startAnimation(animHide);
transparentPanel.setVisibility(View.GONE);
String s=FindFishActivity.this.ongetUrl();
new FetchTask(FindFishActivity.this,s).execute(null);
}
});
in my application i'm using map view which shows spots near my current location.if user click on map pushpin i'm showing detail information about that spot.for showing details ive used some animation part.
in that when user click on hide animation i want to again show the previous map .for showing the animation i've set the content view and again when user click on hide animation i'm calling the function from the main activity(from on create)
so when i call that function its giving me null pointer exception at mapview.
please help!!!
here is my code
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
// searchButton=(Button)findViewById(R.id.searchId);
// searchButton.setOnClickListener(this);
// nearestButton=(Button)findViewById(R.id.nearestId);
// nearestButton.setOnClickListener(this);
url1=ongetUrl();
new FetchTask(FindFishActivity.this, url1).execute(null);
}
private class FetchTask extends AsyncTask<Object,Object,Object>
{
ProgressDialog progressDialog;
Context ctx;
String str_url;
public FetchTask(Context mcontext,String str)
{
this.ctx=mcontext;
this.str_url=str;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=ProgressDialog.show(FindFishActivity.this,"Loading Data","Please wait...");
}
@Override
protected Object doInBackground(Object... params)
{
String res_str=onWebService(str_url);
parse(res_str);
return true;
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
onMapDisplay();
progressDialog.dismiss();
}
public void onMapDisplay() {
String lakeNameString;
setContentView(R.layout.mapview);
mapView=(MapView)findViewById(R.id.mapview);
// if(mapView==null)
// {
// MapView view=new MapView(FindFishActivity.this,"0pPZGIF27HwAISdkPQhUWYj12n5N63e-vAbun1g");
// setContentView(R.layout.mapview);
// }
mapView.setStreetView(true);
mapView.setSatellite(false);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(true);
mapOverlays=mapView.getOverlays();
drawable=FindFishActivity.this.getResources().getDrawable(R.drawable.pushpin4);
myOverlays=new MyOverlays(drawable,FindFishActivity.this);
for(int i=0;i<latitude.size();i++)
{
if(!latitude.get(i).equals(""))
{
lat=Double.parseDouble(latitude.get(i));
latitudearr.add(lat);
}
}
for(int i=0;i<longitude.size();i++)
{
if(!longitude.get(i).equals(""))
{
lon=Double.parseDouble(longitude.get(i));
longitudearr.add(lon);
}
}
for(int i=0;i<lakeNameList.size();i++)
{
if(!lakeNameList.get(i).equals(""))
{
lakeNameString=lakeNameList.get(i);
}
}
for(int k=0;k<latitudearr.size();k++)
{
startPoint=new GeoPoint((int)(latitudearr.get(k) * 1E6),(int)(longitudearr.get(k) * 1E6));
mapController.animateTo(startPoint);
overlayItem=new OverlayItem(startPoint, ""+lakeNameList.get(k).toString(),""+lDescription.toString());
myOverlays.addOverlay(overlayItem);
mapOverlays.add(myOverlays);
mapController.setZoom(6);
mapView.invalidate();
}
}
and for showing animation part
public void onShowInfo() {
setContentView(R.layout.tutorial5);
// LayoutInflater inflater=(LayoutInflater)FindFishActivity.this.getSystemService( Context.LAYOUT_INFLATER_SERVICE);
// View c=inflater.inflate(R.layout.tutorial5,(ViewGroup) findViewById(R.id.linearlayoutID));
transparentPanel=(TransparentPanel)findViewById(R.id.popup_window);
transparentPanel.setVisibility(View.VISIBLE);
transparentPanel.startAnimation(animShow);
final Button hideButton = (Button)findViewById(R.id.hide_popup_button);
hideButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
transparentPanel.startAnimation(animHide);
transparentPanel.setVisibility(View.GONE);
String s=FindFishActivity.this.ongetUrl();
new FetchTask(FindFishActivity.this,s).execute(null);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您没有必要创建单独的布局,即。
教程5
。还有其他方法适合你。在您的
mapview
中添加相对布局并将tutorial5
内容放入其中并具有透明度等。结果:
您将获得顶部带有tutorial5
布局的地图视图。一开始就把它隐藏起来。当用户单击图钉时,只需将可见性设置为View.VISIBLE
,单击停止后将其恢复为View.GONE
。此地图仍将处于活动状态,并且当动画位于顶部时您也可以导航。给出了很好的效果。
PS:将布局
tutorial5
背景颜色设置为#80000000即透明黑色
。我个人很喜欢..:)I dont think it is necessory for you to create separate layout ie.
tutorial5
.There is other way round for you. In your
mapview
add relative layout and puttutorial5
contents in that with transparancy and all that.Result:
You will get mapview with yourtutorial5
layout on top. Just hide it at beginning. when user clicks on pin just set visibility toView.VISIBLE
and after clicking the stop revert it toView.GONE
.With this map will still be active and you can navigate also when animation on top. Gives nice effect.
P.S: set your layout
tutorial5
background colour to#80000000 i.e transparent black
. I personally like it.. :)