이 소스가 EditText에 위치 를 입력하면 찾기 버튼을 통해 위치를 찾는 것인데 그냥 찾기 버튼만 누르면 예를 들어 춘천이 검색 되도록
하려면 어떻게 바꿔야 하나요?? EditText버튼을 없애고 찾기 버튼만 누르면 찾도록 바꾸고 싶습니다
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapDemoC1 extends MapActivity {
MapView mapView;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.map);
final EditText edit = (EditText) findViewById(R.id.edit);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goLoc(edit.getText().toString());
}
});
}
public void goLoc(String goLocName) {
Geocoder gc = new Geocoder(this, Locale.getDefault());
List<Address> adds;
try {
adds = gc.getFromLocationName(goLocName, 1);
if (adds.size() == 0) {
Toast.makeText(this, goLocName+"을 찾을 수 없습니다!", Toast.LENGTH_LONG).show();
return;
}
int latitude = (int) (adds.get(0).getLatitude() * 1E6);
int longitude = (int) (adds.get(0).getLongitude() * 1E6);
GeoPoint gp = new GeoPoint(latitude, longitude);
mapView.getController().setZoom(16);
mapView.getController().setCenter(gp);
mapView.getController().animateTo(gp);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button"
android:text="찾기"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0FZ8rZoSQWpc73uI9RWy9khdTNUVobAR7u3O79g" />
</LinearLayout>
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapDemoC1 extends MapActivity {
MapView mapView;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.map);
Button button = (Button) findViewById(R.id.button);
}
public void goLoc(String goLocName) {
Geocoder gc = new Geocoder(this, Locale.getDefault());
List<Address> adds;
goLoc("춘천");
try {
adds = gc.getFromLocationName(goLocName, 1);
if (adds.size() == 0) {
Toast.makeText(this, goLocName+"을 찾을 수 없습니다!", Toast.LENGTH_LONG).show();
return;
}
int latitude = (int) (adds.get(0).getLatitude() * 1E6);
int longitude = (int) (adds.get(0).getLongitude() * 1E6);
GeoPoint gp = new GeoPoint(latitude, longitude);
mapView.getController().setZoom(16);
mapView.getController().setCenter(gp);
mapView.getController().animateTo(gp);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
이렇게 했는데 버튼이 안먹히네요;




EditText 관련 로직만 제거하고
goLoc("춘천"); 으로 하면?