小编Raf*_*ael的帖子

使用对象数组列表作为微调器适配器

我得到了这个对象的ArrayList,我需要将它设置为我的spinner的适配器,如下所示:

ArrayList<Contact> contactlist= new ArrayList<Contact>();
contactlist.add("Gabe");
contactlist.add("Mark");
contactlist.add("Bill");
contactlist.add("Steve");

ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, contactlist);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

contactsSpinner.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

这是我的Contact对象的一个​​例子,它只有两个变量,Name和ID

Contact contact = new Contact();
    contact.setName("Gabe")
    contact.setID("14575")
Run Code Online (Sandbox Code Playgroud)

我需要让微调器显示来自ArrayList的联系人姓名,因为它显示了内存中的联系地址,选中后,我需要返回联系人ID,以执行其他操作.我怎样才能做到这一点?

user-interface android spinner drop-down-menu

19
推荐指数
1
解决办法
5万
查看次数

Angular 4,将http响应observable转换为object observable

我是可观察的概念的新手,需要一些转换帮助.
我有一个服务Observable<Response>从Http请求返回一个,但我需要转换它做一个在connect方法内部Observable<PriceTag>使用它DataSource.
反正有没有这样做?

这是我服务的方法:

getPriceTags(): Observable<Response> {

    // Set the request headers
    const headers = new Headers({ 'Content-Type': 'application/json' });

    // Returns the request observable
    return this.http.post(Constants.WEBSERVICE_ADDRESS + "/priceTag", null, {headers: headers});

}
Run Code Online (Sandbox Code Playgroud)

这是DataSource类,我需要将其作为以下内容返回Observable<PriceTag>:

export class PriceTagDataSource extends DataSource<PriceTag> {

    constructor (private priceTagService: PriceTagService) {
        super();
    }

    connect(): Observable<PriceTag> {

        // Here I retrieve the Observable<Response> from my service
        const respObs = this.priceTagService.getPriceTags();

        // Now I need to return a Observable<PriceTag> 

    } …
Run Code Online (Sandbox Code Playgroud)

observable rxjs typescript angular

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

如何知道改装调用何时完成

有没有办法知道我的改装电话何时完成了它的职责?我知道什么时候收到所有数据,所以代码可以继续,比如开始另一个活动或者使用第一次调用的数据做一秒钟?

Ps.:我正在使用异步请求(.enqueue).

编辑:

getContact(){ 
//Get a contact List from the server    
    Call<List<ModelContact>> callM =  contactInterface.createRContact(listContact);
    callM.enqueue(new Callback<List<ModelContact>>() {
    @Override

    public void onResponse(Response<List<ModelContact>> response, Retrofit retrofit) {
        // Fetch the List from Response and save it on the local database
        }

    @Override
        public void onFailure(Throwable t) {
            Log.i("TAG", "Error: " + t.getMessage());
        }
    });

    //Gets a object containing some configurations
    Call<Configs> callC = contactInterface.getConfigs(Configs);
    callC.enqueue(new Callback<Configs>() {
    @Override

    public void onResponse(Response<Configs> response, Retrofit retrofit) {
        // Fetch the Configs object and …
Run Code Online (Sandbox Code Playgroud)

api android web-services retrofit retrofit2

8
推荐指数
1
解决办法
5169
查看次数

下拉按钮/ Spinner就像Google的设计规格一样

我想知道如何做一个下拉按钮/菜单,就像我们可以在Google的设计规格和下面的图片中看到的那样,所以列表在按钮下方展开.我是否需要为它设置自定义布局而不是R.layout.support_simple_spinner_dropdown_item

在此输入图像描述

android button drop-down-menu material-design

8
推荐指数
1
解决办法
2万
查看次数

MySql 8.0.11-从5.7更新后找不到mysql.infoschema

今天早上我的mySQL在我的系统上自动从5.7到8.0.11更新.

在此之后,我无法看到任何数据库或在phpMyAdmin上运行任何命令.我尝试做的每件事都会导致涉及mysql.infoschema表格的一些错误.

我得到的大多数错误都是这样的: #1449 - The user specified as a definer ('mysql.infoschema'@'localhost') does not exist

我已经搜索了错误并尝试运行命令来创建用户GRANT ALL ON *.* TO 'someuser'@'%' IDENTIFIED BY 'complex-password'; FLUSH PRIVILEGES;,如此答案中所示.但我不断收到语法错误.

在搜索涉及版本5.7和8.0.11的突发问题后,我在此站点中看到系统表已移至InnoDB.

MySQL的第一个存储引擎 - MyISAM,到目前为止在MySQL中可用.MySQL 5.7仍然使用MyISAM作为MySQL模式中的MySQL权限表,但在MySQL中它们被移动到InnoDB.

我甚至尝试了8.0.11的全新安装,所以我可以导入我的数据库,但是当我尝试以root身份登录时,我得到了相同的#1449错误.

PS.我正在使用Fedora 28.

php mysql fedora phpmyadmin

8
推荐指数
1
解决办法
2939
查看次数

Angular Material 2 - 自动完成中的自定义mat-option/md-option模板

Angular Material 2是否有一个选择器来自定义md-item-templateAngularJS的Angular Material等自动完成选项?我在材料2 的文档中找不到任何内容

来自docs的 AngularJS示例:

<md-autocomplete
    <md-item-template>
      <span class="item-title">
        <md-icon md-svg-icon="img/icons/octicon-repo.svg"></md-icon>
        <span> {{item.name}} </span>
      </span>
      <span class="item-metadata">
        <span class="item-metastat">
          <strong>{{item.watchers}}</strong> watchers
        </span>
        <span class="item-metastat">
          <strong>{{item.forks}}</strong> forks
        </span>
      </span>
    </md-item-template>
</md-autocomplete>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

autocomplete angular-material angular

6
推荐指数
2
解决办法
6324
查看次数

如何等待 Okhttp 调用的结果以在测试中使用它?

我创建了一种方法来检查我的应用程序是否能够使用 OkHttp 连接到我的服务器。

这是我的测试课:

public class NetworkTest {

static boolean resultWeb = false;

public static boolean pingTestWeb() {

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder()
            .url("http://www.google.com")//My server address will go here
            .build();

    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Request request, IOException e) {
            resultWeb = false;
            Log.i("Error","Failed to connect: "+e.getMessage());
        }

        @Override
        public void onResponse(Response response) throws IOException {

            Log.i("Success","Success: "+response.code());
            if (response.code() == 200) {
                resulWeb = true;
            }
        }
    });

    return resultWeb;
}
Run Code Online (Sandbox Code Playgroud)

这是我在 OnCreate() …

connection android timeout ping okhttp

5
推荐指数
2
解决办法
2万
查看次数

TypeScript字符串替换为正则表达式,组和部分字符串

我想在输入时使用正则表达式来格式化输入中的数字.
我的问题是:由于我使用组来格式化数字,它只在字符串与正则表达式匹配时才格式化.这是一个例子:
完整的数字是:12312312312| 格式化看起来像:123.123.123-12.

如果我输入1231231例如,它不会123.123.1像我期望的那样格式化,只有当我键入整个数字时.

这是我的功能:

format(value){
    // This function returns the formatted string on user input
    return value.replace(/(\d{3})(\d{3})(\d{3})(\d+)/, "\$1.\$2.\$3-\$4");
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让其余的组选项?

regex replace typescript

4
推荐指数
1
解决办法
1万
查看次数