作者joylo (SOC.梦街)
看板java
标题Re: [J2SE] android menu 资料连结问题?
时间Thu Apr 2 09:58:44 2009
※ 引述《PHILLLU (PHILLU)》之铭言:
: 各位大大好
: 小弟我 目前在写android 的应用程式
: 目前遇到了一个问题 因为我要运用 下面一个类别的变数 该如何把
: menu 与 下面一个类别做连结呢? 谢谢 我是用Eclipse 的
: public boolean onOptionsItemSelected(MenuItem item)
: {
: switch(item.getItemId()){
: case 1:
: onLocationChanged(Location loc);-------> X 显示错误
: int s= 5; -------->示意
: return true;
: case 2:
: onLocationChanged(Location loc);-------------------->X 显示错误
: int s= 10; ------> 示意
: return true;
: }
: return true;
: }
: public class MyLocationListener implements LocationListener {
: public void onLocationChanged(Location loc) {
: if (loc != null) {
: //show location in TextView
: TextView TV =(TextView)findViewById(R.id.latlon);
: String strlat = Double.toString(loc.getLatitude());
: String strlon = Double.toString(loc.getLongitude());
: String imageUrl = s; --------> 要让menu 来修改 s变书
很难说哪种方式解决比较好 因为方法满多的XD
你可以考虑在第二个class用一个建构子去接s值
然後在第一个class写一个丢s值进第二个class建构子的语法
也可以把你的onLocationChanged的呼叫语法写在建构子里
那你第一个class里的switch case就只需要呼叫yLocationListener建构子
并传loc跟s值即可,再由建构子内的呼叫语法将loc跟s传进method里
举例就是
myLocationListenr(Loction loc, String s)
{
this.onLocationChanged(loc, s);
}
不知道这样解释能了解吗^^b....
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.229.203.88