小编mav*_*ros的帖子

XML 中默认条目的 Android Spinner 项目布局

我有两个微调器。其中之一在运行时填充。

groupSpinner.setAdapter(new ArrayAdapter<>(this,
                 android.R.layout.simple_spinner_item, groupNames));
Run Code Online (Sandbox Code Playgroud)

另一个是使用字符串数组预先填充在 XML 布局中。

<Spinner ...
    android:entries="@array/my_items_here" />
Run Code Online (Sandbox Code Playgroud)

两个 Spinner 看起来都很好。但是,当他们的项目显示时,子布局dropdowndialog模式和模式中都不匹配。我一定遗漏了一些非常简单的东西,但是如何将它们设置为使用相同的布局(希望如此android.R.layout.simple_spinner_item),而不创建我自己的自定义布局,或者在运行时加载 XML 字符串数组?

这似乎是一件基本的事情,但我找不到答案,而且我已经搜索了很多。

请参阅以下屏幕截图:

以编程方式填充的微调器 XML 预填充 Spinner

*请原谅在第二张图片中使用了希腊字符。我已经检查并确认问题与希腊字符的使用无关。

java android android-layout android-xml android-spinner

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

有效地使用Delphi从文件中读取未知大小的块

在过去,我看过这项工作,但我从未真正理解应该如何做.
假设我们有一个已知数据类型文件,但未知长度,如动态数组TSomething,其中

type
  TSomething = class
    Name: String;
    Var1: Integer;
    Var2: boolean;
  end;
Run Code Online (Sandbox Code Playgroud)

但问题是,将来可能会扩展此对象类型,添加更多变量(例如Var3: String).
然后,使用旧版本保存的文件将不包含最新的变量.
文件读取过程应该以某种方式识别中的数据,使用如下算法:

procedure Read(Path: String)
begin
  // Read Array Size
  //   Read TSomething --> where does this record end? May not contain Var3!
  //   --> how to know that the next data block I read is not a new object?
end;
Run Code Online (Sandbox Code Playgroud)

我已经看过这个工作BlockReadBlockWrite …

delphi

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

如何在对话框中将layout params设置为edittext?

我试图在对话框中为一个edittext设置一些布局参数,但它似乎没有任何效果.为什么?如何减小编辑文本的宽度?

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder = new AlertDialog.Builder(context);
final EditText input = new EditText(context);                    
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(20, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 0, 10, 0);  
input.setLayoutParams(lp); 

builder.setView(input)
.setCancelable(false)                   
.setPositiveButton(res.getString(R.string.ok), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
             //...   
    }
})
.setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        dialog.cancel();
    }
});
Run Code Online (Sandbox Code Playgroud)

android dialog layoutparams

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

我可以将反射与 ProGuard 混淆类一起使用吗?

我有一个我想invoke使用的类方法Reflection
这是我的代码示例Activity onCreate

try {
    aMethod = getClass().getDeclaredMethod("myMethodName", SomeParameter.class);
} catch (NoSuchMethodException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

当我直接从 Android Studio 运行它时,它可以工作,但是当我创建发布版本时,ProGuard 不会自动更改方法名称。我能做什么?

java reflection android proguard

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

如何修复IllegalMonitorStateException

我在我的代码中遇到IllegalMonitorStateException,我不知道为什么我收到它以及如何解决它.我当前的代码是,并且try块中发生错误:

  public static String scrapeWebsite() throws IOException {

    final WebClient webClient = new WebClient();
    final HtmlPage page = webClient.getPage(s);
    final HtmlForm form = page.getForms().get(0);
    final HtmlSubmitInput button = form.getInputByValue(">");
    final HtmlPage page2 = button.click();
    try {
    page2.wait(1);
    }
    catch(InterruptedException e)
    {
      System.out.println("error");
    }
    String originalHtml = page2.refresh().getWebResponse().getContentAsString();
    return originalHtml;
  }
}
Run Code Online (Sandbox Code Playgroud)

java error-handling wait

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