小编Woo*_*off的帖子

无法从PlaceBuffer获取特定地点

我有一个特定的地方有奇怪的问题.任何的想法 ?

这段代码运行正常,但是对于一个地方(由于aaa启动而意外选择 - 仅用于测试),它无法从缓冲区获取Place对象.甚至查询也是成功的(日志:PlaceAutocompleteAdapt:查询已完成.收到5个预测.)不幸的是,它崩溃了应用程序.它使这个API非常危险,还有什么应该在try catch块中处理?

        addressAutocompleteText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            /*
             Retrieve the place ID of the selected item from the Adapter.
             The adapter stores each Place suggestion in a PlaceAutocomplete object from which we
             read the place ID.
              */
            final PlaceAutocompleteAdapter.PlaceAutocomplete item = ((MainActivity) getActivity()).mAdapter.getItem(position);
            final String placeId = String.valueOf(item.placeId);
            Log.i(TAG, "Autocomplete item selected: " + item.description);

            /* Issue a request to the Places Geo Data API to …
Run Code Online (Sandbox Code Playgroud)

android google-places-api google-places

10
推荐指数
2
解决办法
2648
查看次数

如何防止在DatePickerDialog中选择传递日期(setMinDate无法按预期工作)

我发现DatePicker(Dialog)非常令人困惑......当设置setMinDate()时...显示的日历真的"视觉上禁用"传递日期(使它们变灰)但这些日期仍然可供选择!我想用户阻止这样做.理想的方法是使通过的日期不可点击/不可选.如果不可能,至少要抓住这个事件(哪一个?onDateChanged?,onSelected?...)并保留一条消息并禁用OK按钮,直到用户选择一个有效的日期.

不幸的是,datepicker(对话框)没有onChangedListener(实际上它有但没有setter).所以我得到的唯一事件是按下OK按钮.为时已晚.

这是我的代码

    dateTextView = (TextView) view.findViewById(R.id.createOrder_date);
    dateTextView.setText(R.string.createOrder_time_now);
    dateTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Calendar calendarNow = Calendar.getInstance();
            final int yearNow = calendarNow.get(Calendar.YEAR);
            final int monthNow = calendarNow.get(Calendar.MONTH);
            final int dayNow = calendarNow.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog datePickerDialog = new DatePickerDialog(CreateOrderFragment.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(year, monthOfYear, dayOfMonth);

                    if (calendar.before(calendarNow)) {
                        Toast.makeText(CreateOrderFragment.this.getActivity(), getResources().getString(R.string.createOrder_datePicker_selectFutureDate), Toast.LENGTH_SHORT).show();
                        view.updateDate(yearNow, monthNow, dayNow);
                        calendar = calendarNow;
                    }

                    SimpleDateFormat sdf = …
Run Code Online (Sandbox Code Playgroud)

android android-datepicker datepickerdialog android-5.0-lollipop

7
推荐指数
1
解决办法
2500
查看次数

android SyncAdapter中的异步齐射调用

我使用齐射库实现了SyncAdapter.它正在工作,但后来我意识到Iam从onPerformSync方法调用异步(排球请求)代码.

  • Q1:coudl是onPerformSync并行多次执行?(对于一个用户/一个权限).我需要编写内码安全吗?用锁?同步?SyncAdapter本身不是同步的,所以任何内部同步都没用吗?
  • Q2:是onPerformSync线程安全,哪个线程?在我看来,所有onPerformSync调用都是由相同的线程引用完成的.这是否意味着SyncAdapter实际上被系统多次重用?
  • Q3:在同步代码完成之前结束onPerformSync是否安全?(凌空调用可能比创建截击请求,运行它并完成更长时间)
    @Override
    public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient contentProviderClient, SyncResult syncResult) {
        JsonObjectRequest jsObjRequest = new JsonObjectRequest
                (Request.Method.GET, url, null, new Response.Listener() {
                    @Override
                    public void onResponse(JSONObject response) {
                        // time consuming code
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // TODO Auto-generated method stub
                    }
                });
        // Access the RequestQueue through your singleton class.
        MySingleton.getInstance(this).addToRequestQueue(jsObjRequest);
        // onPerformSync end reached before volley request processing ends
    }
Run Code Online (Sandbox Code Playgroud)

concurrency multithreading android asynchronous android-syncadapter

6
推荐指数
1
解决办法
305
查看次数

如何在JSF2/EL 2.2中使用可选参数列表调用方法

任何想法如何(如果可能)用JSF页面中的可选参数调用java方法?我使用Java 7,JSF 2.1,EL 2.2(Glassfish 3.1.2).提前致谢...

我得到了这个例外

javax.el.ELException: /example.xhtml: wrong number of arguments
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
Run Code Online (Sandbox Code Playgroud)

页面示例

<h:outputText value="#{bean.methodWithParameters('key.en.currentDate', '2012-01-01', '00:00')}"/>
<h:outputText value="#{bean.methodWithParameters('key.en.currentTime', '12:00')}"/>
Run Code Online (Sandbox Code Playgroud)

豆的例子

public String methodWithParameters(String key, Object ... params) {
    String langValue = LanguageBean.translate(key);
    return String.format(langValue, params);
}
Run Code Online (Sandbox Code Playgroud)

属性示例

key.en.currentDate=Today is %s and current time is %s.
key.en.currentTime=Current time is %s.

key.en.currentDate=Today is %1$s and current time is %2$s.
key.en.currentTime=Current time is %2$s.
Run Code Online (Sandbox Code Playgroud)

java el optional-parameters optional-arguments jsf-2

3
推荐指数
1
解决办法
1514
查看次数