したがって、メインクラスと、メインクラスに引き出す必要のある変数を持つ別のクラスがあります。私はこのように答えられた質問に投稿されたいくつかの方法を試しましたが、それでも正しく理解できていません。
public class Example extends MapActivity
{
public void OnCreate(Bundle savedInstanceState){
final Button bttn = (Button)findViewById(R.id.button1);
bttn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast tulos = Toast.makeText(getBaseContext(),
"Area is: "
+MyItemizedOverlay.alue +""
/*I get the non static variable error here
which I get as it is not yet defined, it will be after the user
inputs values into the program*/
,Toast.LENGTH_LONG);
tulos.show();
}
});
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
int alue;
//irreleveant stuff (I assume)
public void Calc(Geopoint gp, Mapview map){
//there's some stuff before the variable I want to get like other variables
//not relevant for my problem I hope
alue = (int)Math.round(*formula: derived from user input data*)
}
}
では、他のクラスから値を取得するにはどうすればよいでしょうか。現在は取得できないようです。それとも、これはより大きな問題を示しているのでしょうか?