在我的 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();
}
}