我通過對話題的線索負荷去,但我沒能找到解決我的問題。傳遞緯度和經度到另一個活動
我想寫這將顯示存儲在SQLlite DB一旦用戶點擊了他們應提請在顯示地圖的另一個活動中的一個條目GPS座標列表中的應用程序。
我的目錄活動看起來像這樣:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.coordinates_activity);
mListView = (ListView) findViewById(R.id.listview);
mAdapter = new SimpleCursorAdapter(getBaseContext(),
R.layout.item_layout,
null,
new String[] {LocationsDB.FIELD_ROW_ID, LocationsDB.FIELD_LAT, LocationsDB.FIELD_LNG},
new int[] {R.id.row_id, R.id.row_lat, R.id.row_lgt }, 0);
mListView.setAdapter(mAdapter);
getSupportLoaderManager().initLoader(0, null, this);
mListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View v, int position, long id){
Intent intentlist = new Intent(getApplicationContext(),fromlist.class);
startActivity(intentlist);
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
Uri uri = LocationsContentProvider.CONTENT_URI;
return new CursorLoader(this, uri, null, null, null, null);
}
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
mAdapter.swapCursor(arg1);
}
public void onLoaderReset(Loader<Cursor> arg0) {
mAdapter.swapCursor(null);
}
}
我已經更新了onItemClick到:
mListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View v, int position, long id){
TextView tv1=(TextView)v.findViewById(R.id.row_lat);
String lon_map=tv1.getText().toString();
Double lon1 = Double.parseDouble(lon_map);
TextView tv2=(TextView)v.findViewById(R.id.row_lgt);
String lgt_map=tv2.getText().toString();
Double lgt2 = Double.parseDouble(lgt_map);
Intent intentlist = new Intent(getApplicationContext(),fromlist.class);
intentlist.putExtra("lon1", lon1);
intentlist.putExtra("lgt2", lgt2);
startActivity(intentlist);
}
第二個活動是這樣的:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fromlist_activity);
double latitude = getIntent().getDoubleExtra("lon1", 0);
double longitude = getIntent().getDoubleExtra("lgt2", 0);
我仍然不能得到第二項活動中的數值爲
什麼是您的具體問題? – 2014-12-02 21:50:31
您需要使用意圖 – SeahawksRdaBest 2014-12-02 21:52:23
如何將存儲的R.id.row_lat和R.id.row_lgt的值存儲到另一個活動中。 – user1380840 2014-12-02 21:52:57