请,我一直在尝试将 ListView 添加到正在开发的 android 应用程序中,但是当我添加 ListView 时它总是启动然后崩溃。我需要帮助。我试过谷歌搜索寻求帮助,但没有找到。我不知道为什么它不起作用。下面是我的 MainActivity.java
public class MainActivity extends FragmentActivity {
private GoogleMap maap;
static final String[] OptionS = new String[]{"for 1","for 2","for 3","for 4"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView listView= (ListView) findViewById(R.id.listView1);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
setContentView(R.layout.activity_main);
getActionBar().setDisplayHomeAsUpEnabled(true);
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
maap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
maap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
maap.getUiSettings().setMyLocationButtonEnabled(true);
maap.getUiSettings().setAllGesturesEnabled(true);
CameraPosition Position =new CameraPosition.Builder()
.target(new LatLng(33.53,10.08))
.zoom(7.2f)
.tilt(40)
.build();
CameraUpdate Update = CameraUpdateFactory.newCameraPosition(Position);
maap.moveCamera(Update);
maap.addMarker(new MarkerOptions()
.position(new LatLng(33.53,10.08))
.title("TEST")
.draggable(true)
.snippet("is good"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
startActivity(new Intent(this, ActivityMenus.class));
case R.id.item2:
startActivity(new Intent(this, ActivityMenus.class));
case R.id.item3:
startActivity(new Intent(this, ActivityMenus.class));
case R.id.item4:
startActivity(new Intent(this, ActivityMenus.class));
}
return true;
}
}