1

在我的 MapView 中显示了这样的气球:http://www.codemobiles.com/forum/code-mobile-topic-4180.html(它或多或少相同的代码)我想要什么:如果我按气球1 它应该用 1 的信息打开详细视图,当我按下气球 2 它应该用 2 的信息打开详细视图

我将此添加到逐项叠加: c.startActivity(new Intent(c.getApplicationContext(), QuoteDetail.class));

因此,当我按下 Balloon 1 时,它会打开带有 Information 1 的 DetailView 但是当我按下 Balloon 2 时,它也会打开带有 Information 1 的 DetailView 我该如何更改?

这是我的代码: QuoteDetail:

private ImageView mImageView;
private TextView mQuote;
private TextView mInfo;
private TextView mEmail;
private TextView mTel;
private TextView mWww;
private int mPosition;
private DataSource mDataSource;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.quote_detail);

    Intent i = getIntent();
    mPosition = i.getIntExtra("position", 0);

    mDataSource = new DataSource();
    mImageView = (ImageView) findViewById(R.detail.image);
    mQuote = (TextView) findViewById(R.detail.quote);
    mInfo = (TextView) findViewById(R.detail.info);
    mEmail = (TextView) findViewById(R.detail.email);
    mTel = (TextView) findViewById(R.detail.tel);
    mWww = (TextView) findViewById(R.detail.www);

    mImageView.setImageResource(mDataSource.getmPhotoHdPool().get(mPosition));
    mQuote.setText(getResources().getString(mDataSource.getmQuotePool().get(mPosition)));
    mInfo.setText(getResources().getString(mDataSource.getmInfoPool().get(mPosition)));
    mEmail.setText(getResources().getString(mDataSource.getmEmailPool().get(mPosition)));
    mTel.setText(getResources().getString(mDataSource.getmTelPool().get(mPosition)));
    mWww.setText(getResources().getString(mDataSource.getmWwwPool().get(mPosition)));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
   getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;  }





    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_me:  startActivity(new Intent(this, AboutmeActivity.class));;
                                break;

            case R.id.menu_settings:  startActivity(new Intent(this, SettingsActivity.class));;
            break;
        }
        return true;  }

}

QuoteReader 活动:

public class QuoteAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflator;
    private DataSource mDataSource;

    public QuoteAdapter(Context c) {
        mContext = c;
        mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mDataSource = new DataSource();
    }


    public int getCount() {
        return mDataSource.getDataSourceLength();
    }


    public Object getItem(int position) {
        return position;
    }


    public long getItemId(int position) {
        return position;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView thumbnail;
        TextView quote;

        if(convertView == null) {
            convertView = mInflator.inflate(R.layout.list_item_layout, parent, false);
        }

        thumbnail = (ImageView) convertView.findViewById(R.list.thumb);
        thumbnail.setImageResource(mDataSource.getmPhotoPool().get(position));

        quote = (TextView) convertView.findViewById(R.list.text);
        quote.setText(mDataSource.getmQuotePool().get(position));
        return convertView;
    }
}

// Rest of QuoteReaderActivty class...

private ListView mListView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mListView = (ListView) findViewById(R.id.quotes_list);
    mListView.setAdapter(new QuoteAdapter(this));

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                long arg3) {
            Intent i = new Intent(QuoteReaderActivity.this, QuoteDetail.class);
            i.putExtra("position", position);
            startActivity(i);
        }


    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
   getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;  }


    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_me:  startActivity(new Intent(this, AboutmeActivity.class));;
                                break;

            case R.id.menu_settings:  startActivity(new Intent(this, SettingsActivity.class));;
            break;
        }
        return true;  }

}

日期来源:

public ArrayList<Integer> getmPhotoHdPool() {
    return mDetail;
}

public ArrayList<Integer> getmWwwPool() {
    return mWww;
}

public ArrayList<Integer> getmTelPool() {
    return mTel;
}

public ArrayList<Integer> getmInfoPool() {
    return mInfo;
}

public ArrayList<Integer> getmEmailPool() {
    return mEmail;
}
public ArrayList<Integer> getmPhotoPool() {
    return mList;
}

public ArrayList<Integer> getmQuotePool() {
    return mText;
}

private void setupPhotoPool() {
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);
    mList.add(R.drawable.tcs_1);

}

private void setupQuotePool() {
    mText.add(R.string.quote_1);
    mText.add(R.string.quote_2);
    mText.add(R.string.quote_3);
    mText.add(R.string.quote_4);
    mText.add(R.string.quote_5);
    mText.add(R.string.quote_6);
    mText.add(R.string.quote_7);
    mText.add(R.string.quote_8);
    mText.add(R.string.quote_9);
    mText.add(R.string.quote_10);
    mText.add(R.string.quote_001);


}

private void setupEmailPool() {
    mEmail.add(R.string.email_1);
    mEmail.add(R.string.email_2);
    mEmail.add(R.string.email_3);
    mEmail.add(R.string.email_4);
    mEmail.add(R.string.email_5);
    mEmail.add(R.string.email_6);
    mEmail.add(R.string.email_7);
    mEmail.add(R.string.email_8);
    mEmail.add(R.string.email_9);
    mEmail.add(R.string.email_10);
    mEmail.add(R.string.email_001);


}

private void setupTelPool() {
    mTel.add(R.string.tel_1);
    mTel.add(R.string.tel_2);
    mTel.add(R.string.tel_3);
    mTel.add(R.string.tel_4);
    mTel.add(R.string.tel_5);
    mTel.add(R.string.tel_6);
    mTel.add(R.string.tel_7);
    mTel.add(R.string.tel_8);
    mTel.add(R.string.tel_9);
    mTel.add(R.string.tel_10);
    mTel.add(R.string.tel_001);


}

private void setupWwwPool() {
    mWww.add(R.string.www_1);
    mWww.add(R.string.www_2);
    mWww.add(R.string.www_3);
    mWww.add(R.string.www_4);
    mWww.add(R.string.www_5);
    mWww.add(R.string.www_6);
    mWww.add(R.string.www_7);
    mWww.add(R.string.www_8);
    mWww.add(R.string.www_9);
    mWww.add(R.string.www_10);
    mWww.add(R.string.www_001);


}
private void setupPhotoHDPool() {
    mDetail.add(R.drawable.caming_hd_1);
    mDetail.add(R.drawable.caming_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);
    mDetail.add(R.drawable.camping_hd_1);}


       private void setupInfoPool() {
            mInfo.add(R.string.detail_1);
            mInfo.add(R.string.detail_2);
            mInfo.add(R.string.detail_3);
            mInfo.add(R.string.detail_4);
            mInfo.add(R.string.detail_5);
            mInfo.add(R.string.detail_6);
            mInfo.add(R.string.detail_7);
            mInfo.add(R.string.detail_8);
            mInfo.add(R.string.detail_9);
            mInfo.add(R.string.detail_10);
            mInfo.add(R.string.detail_001);





}

public int getDataSourceLength() {
    return mList.size();
}

public DataSource() {
    mList = new ArrayList<Integer>();
    mText = new ArrayList<Integer>();
    mInfo = new ArrayList<Integer>();
    mDetail = new ArrayList<Integer>();
    mEmail = new ArrayList<Integer>();
    mTel = new ArrayList<Integer>();
    mWww = new ArrayList<Integer>();
    setupPhotoPool();
    setupQuotePool();
    setupInfoPool();
    setupPhotoHDPool();
    setupEmailPool();
    setupTelPool();
    setupWwwPool();




}

}

4

2 回答 2

0

我也在使用这个链接,http://www.codemobiles.com/forum/code-mobile-topic-4180.html 一些代码被添加,

MyMap.java 类

public class MyMap extends MapActivity {

MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
MyItemizedOverlay itemizedOverlay;
//MyItemizedOverlay itemizedOverlay2;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    mapOverlays = mapView.getOverlays();

    // first overlay
    drawable = getResources().getDrawable(R.drawable.marker);
    itemizedOverlay = new MyItemizedOverlay(drawable, mapView);

    GeoPoint point = new GeoPoint((int) (51.5174723 * 1E6),
            (int) (-0.0899537 * 1E6));
    OverlayItem overlayItem = new OverlayItem(point, "Umar Shafique",
            "(here goes 1)");
    itemizedOverlay.addOverlay(overlayItem);

    GeoPoint point2 = new GeoPoint((int) (51.515259 * 1E6),
            (int) (-0.086623 * 1E6));
    OverlayItem overlayItem2 = new OverlayItem(point2, "Abdul Karim",
            "here goes 2");
    itemizedOverlay.addOverlay(overlayItem2);

    mapOverlays.add(itemizedOverlay);

    // second overlay
/*  drawable2 = getResources().getDrawable(R.drawable.marker2);
    itemizedOverlay2 = new MyItemizedOverlay(drawable2, mapView);

    GeoPoint point3 = new GeoPoint((int) (51.513329 * 1E6),
            (int) (-0.08896 * 1E6));
    OverlayItem overlayItem3 = new OverlayItem(point3, "Arslan Ilyas",
            "here goes 3");
    itemizedOverlay2.addOverlay(overlayItem3);

    GeoPoint point4 = new GeoPoint((int) (51.51738 * 1E6),
            (int) (-0.08186 * 1E6));
    OverlayItem overlayItem4 = new OverlayItem(point4, "Ahsan",
            "here goes 4");
    itemizedOverlay2.addOverlay(overlayItem4);

    mapOverlays.add(itemizedOverlay2);*/

    final MapController mc = mapView.getController();
    mc.animateTo(point2);
    mc.setZoom(16);

}

@Override
protected boolean isRouteDisplayed() {
    return false;
}

}

这里我注释了一些代码,因为这里添加了两个 itemizedOverlay ,所以一个是注释。

和 MyItemizedOverlay.java 类

public class MyItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;

public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
    super(boundCenter(defaultMarker), mapView);
    c = mapView.getContext();
}

public void addOverlay(OverlayItem overlay) {
    m_overlays.add(overlay);
    populate();
}

@Override
protected OverlayItem createItem(int i) {
    return m_overlays.get(i);
}

@Override
public int size() {
    return m_overlays.size();
}

@Override
protected boolean onBalloonTap(int index) {
    Toast.makeText(c, "onBalloonTap for overlay index " + index,
            Toast.LENGTH_LONG).show();

    if (index == 0) {
        c.startActivity(new Intent(c.getApplicationContext(),
                NewActivity.class));
    } else {
         c.startActivity(new Intent(c.getApplicationContext(),
         secondNewActivity.class));
    }
    return true;
}

}

这里修改代码

  if (index == 0) {
        c.startActivity(new Intent(c.getApplicationContext(),
                NewActivity.class));
    } else {
         c.startActivity(new Intent(c.getApplicationContext(),
         secondNewActivity.class));
    }
    return true;
}

按气球二,我们可以改变索引位置。我们可以通过您的意图传递索引位置。

提供您的代码,只有 Easy the Explain。

于 2012-08-03T05:57:03.240 回答
0

在 Itemized Overlay onClick 处理程序中,添加一个 intentExtra,以便您可以将识别信息传递给您的 QuoteDetail.class。您很可能希望使用自己的类扩展 ItemizedOverlay 类,添加可用于标识项目的成员变量。然后只需访问这些成员变量并将它们作为 intentExtras 传递给 QuoteDetail。

于 2012-08-02T17:34:21.697 回答