Set an onClickListner method to MapActivity
1)
First do the setContentView, after that the Button is findable. The system could not find your Button now, so that's why it is a null. Your MapView map also would be a null in your code. 2) If you define an object within {} it is only available within that {} You probably going to need the Object "but" later, so make it a private variable of the class. 3) Classname should start with a capital. 4) Visit anddev.org or some site like that for coding problems, xda seems to be more focused on system/firmware issues, not application code. So, this should work: public class MainActivity extends MapActivity { final Button but; final MapView map; @Override public boolean isRouteDisplayed() { return false; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); but = (Button) findViewById(R.id.gpsButton); but.setOnClickListener(new View.OnClickListener() { public void onClick(View v){ } }); map = (MapView) findViewById(R.id.myMap); } } | |
No comments:
Post a Comment