버튼을 꼭 두번눌러야 실행이 됩니다...
조회수 904회
버튼을 두번씩 눌러야 실행이 되고 값을 입력 안하면 첫번째 if문에 걸려서 toast를 출력해줘야하는데 되지가 않습니다..... 왜그런건가요...? 코드상 문제는 없어보여서 부탁드립니다!!
public class kakao extends AppCompatActivity implements MapView.POIItemEventListener {
private Button btn_find;
private EditText input;
private MapView mapView ;
private int i,tag;
private ArrayList<MapPOIItem> markerlist;
private ArrayList<MarkerInfo> markerinfo;
private int count;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_kakao);
btn_find = findViewById(R.id.btn_place2);
input = findViewById(R.id.input_place2);
mapView= new MapView(this);
ViewGroup mapViewContainer = (ViewGroup) findViewById(R.id.map_view2);
mapViewContainer.addView(mapView);
markerlist = new ArrayList<MapPOIItem>();
markerinfo = new ArrayList<MarkerInfo>();
markerlist.clear();
markerinfo.clear();
btn_find.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(input.getText()==null){
Toast.makeText(kakao.this, "장소를 입력하세요!", Toast.LENGTH_SHORT).show();
}
else{
int tagindex=0;
if(false==markerlist.isEmpty()){
for(i=0;i<markerlist.size();i++){
mapView.removePOIItem(markerlist.get(i));
}
markerlist.clear();
markerinfo.clear();
}
MarkerInfoCall();
for(i=0;i<markerinfo.size();i++) {
MapPoint centpoint = MapPoint.mapPointWithGeoCoord(markerinfo.get(0).lat,markerinfo.get(0).lng);
mapView.setMapCenterPoint(centpoint, true);
MapPoint mapPoint = MapPoint.mapPointWithGeoCoord(markerinfo.get(i).lat, markerinfo.get(i).lng);
MapPOIItem marker = new MapPOIItem();
marker.setItemName(markerinfo.get(i).name);
marker.setMapPoint(mapPoint);
marker.setTag(tagindex);
marker.setShowCalloutBalloonOnTouch(false);
marker.setShowAnimationType(MapPOIItem.ShowAnimationType.SpringFromGround);
marker.setMarkerType(MapPOIItem.MarkerType.YellowPin); // 기본으로 제공하는 BluePin 마커 모양.
marker.setSelectedMarkerType(MapPOIItem.MarkerType.BluePin); // 마커를 클릭했을때, 기본으로 제공하는 RedPin 마커 모양.
mapView.addPOIItem(marker);
markerlist.add(marker);
tagindex++;
}
}
}
});
MapPoint mapPoint = MapPoint.mapPointWithGeoCoord(37.53737528, 127.00557633);
mapView.setMapCenterPoint(mapPoint, true);
mapView.setPOIItemEventListener(this);
}
public void onPOIItemSelected(MapView mapView, MapPOIItem mapPOIItem) {
String place_name = mapPOIItem.getItemName();
tag = mapPOIItem.getTag();
showAlertDialog(place_name);
}
@Override
public void onCalloutBalloonOfPOIItemTouched(MapView mapView, MapPOIItem mapPOIItem) {
}
@Override
public void onCalloutBalloonOfPOIItemTouched(MapView mapView, MapPOIItem mapPOIItem, MapPOIItem.CalloutBalloonButtonType calloutBalloonButtonType) {
}
@Override
public void onDraggablePOIItemMoved(MapView mapView, MapPOIItem mapPOIItem, MapPoint mapPoint) {
}
private void showAlertDialog(String place_name){
AlertDialog.Builder builder = new AlertDialog.Builder(kakao.this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.map_info,null);
builder.setView(view);
TextView title = view.findViewById(R.id.map_title);
TextView addr = view.findViewById(R.id.map_addr);
Button btn_road = view.findViewById(R.id.btn_road);
Button btn_info = view.findViewById(R.id.btn_info);
Button btn_call = view.findViewById(R.id.btn_call);
final AlertDialog dialog = builder.create();
title.setText(place_name);
addr.setText(markerinfo.get(tag).address);
btn_call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+markerinfo.get(tag).phone)));
}
});
btn_road.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(kakao.this, "kkkk", Toast.LENGTH_SHORT).show();
}
});
btn_info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(kakao.this, Web_Place_Info.class);
intent.putExtra("url",markerinfo.get(tag).link);
startActivity(intent);
}
});
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setGravity(Gravity.BOTTOM);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.show();
}
private void MarkerInfoCall(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://dapi.kakao.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
String KaKaoAK = "KakaoAK ㅌㅌㅌㅌㅌㅌ";
String query = String.valueOf(input.getText());
KaKaoInterface service = retrofit.create(KaKaoInterface.class);
Call<KaKaoRepo> call =service.kakaorepo(KaKaoAK,query);
call.enqueue(new Callback<KaKaoRepo>() {
@Override
public void onResponse(Call<KaKaoRepo> call, Response<KaKaoRepo> response) {
Log.d("sssssss", String.valueOf(response.code()));
if(response.isSuccessful()){
Log.d("dddddd", String.valueOf(response.code()));
KaKaoRepo result = response.body();
if(result.documents.length != 0){
int count = result.meta.getTotal_count();
if(count>15){
count=15;
}
for(i=0;i<count;i++){
MarkerInfo mki = new MarkerInfo();
mki.setAddress(result.documents[i].getRoad_address_name());
mki.setCategory(result.documents[i].getCategory_name());
mki.setName(result.documents[i].getPlace_name());
mki.setPhone(result.documents[i].getPhone());
mki.setLink(result.documents[i].getPlace_url());
mki.setLng(result.documents[i].getX());
mki.setLat(result.documents[i].getY());
markerinfo.add(mki);
}
Log.d("사이즈", String.valueOf(markerinfo.size()));
}
else{
Toast.makeText(kakao.this, "No Data", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(kakao.this, "API Error", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<KaKaoRepo> call, Throwable t) {
Log.e("에러", String.valueOf(t));
}
});
}
}
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력