线程计时器多个if语句不起作用

时间:2016-05-17 13:16:56

标签: java android multithreading google-maps

我使用意图和谷歌地图专注于用户点击listview中显示的地方的标记。我在onResume()中使用线程计时器来执行此操作.... 问题是当我运行我的问题并只使用一个焦点标记,即此代码运行正常并专注于标记

@Override
protected void onResume() {
    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(1000);
            } catch (InterruptedException e){
                e.printStackTrace();
            } finally {

                MainActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Intent intent = getIntent();
                        String restaurant_name = intent.getStringExtra("restaurant_name");
                        //Toast.makeText(MainActivity.this, restaurant_name, Toast.LENGTH_LONG).show();

                        if(restaurant_name != null ) {
                            if (restaurant_name.equals("place1")) {
                                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89192, 75.82441), 15.0f));
                                mMap.addMarker(new MarkerOptions()
                                        .position(new LatLng(26.89192, 75.82441))
                                        .title("place1"))
                                        .showInfoWindow();
                            }



                            }else {
                            MainActivity.this.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    //Toast.makeText(MainActivity.this, "It was not", Toast.LENGTH_LONG).show();
                                }
                            });

                        }
                    }
                });
   /* Toast.makeText(MainActivity.this, restaurant_name, Toast.LENGTH_LONG).show(); */

            }
        }
    };
    timer.start();

    super.onResume();

}
只要我在那里放置另一个焦点标记,即

if(restaurant_name != null ) {
                            if (restaurant_name.equals("place1")) {
                                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89192, 75.82441), 15.0f));
                                mMap.addMarker(new MarkerOptions()
                                        .position(new LatLng(26.89192, 75.82441))
                                        .title("place1"))
                                        .showInfoWindow();
                            }

                            if (restaurant_name.equals("place2")) {
                                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89510, 75.82594), 15.0f));
                                mMap.addMarker(new MarkerOptions()
                                        .position(new LatLng(26.89510, 75.82594))
                                        .title("place2"))
                                        .showInfoWindow();


                            }

                            }

第二个代码不关注标记,但第一个代码确实..

我的意图是我的列表视图基本适配器:

String value = holder.txtStore.getText().toString();
            Intent myIntent = new Intent(view.getContext(), MainActivity.class);
            myIntent.putExtra("restaurant_name", value);
            try {
                context.startActivity(myIntent);
            } catch (android.content.ActivityNotFoundException ex) {
                ex.printStackTrace();
                Toast.makeText(context, "yourActivity is not founded", Toast.LENGTH_SHORT).show();
            }

我应该怎么做才能为每个焦点标记工作我想要插入很多,我用过if if if else切换所有这些但是什么都没有用?

0 个答案:

没有答案