编辑:对不起,我从你的评论中意识到我的问题不够明确.我会发一个新的.对不起,谢谢你的回答
我正在从Json文件填充listview.使用listadapter,我可以轻松地将相应的json数据分配给列表的每一行.这适用于文本,例如:
TextView tv = (TextView)ll.findViewById(R.id.descView);
tv.setText(i.desc);
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,每个行都将由良好的json数据正确填充.
但是,我无法为图像做同样的事情.我试图使用以下方法从我的json数据中设置正确的图像:
ImageView iv = (ImageView)ll.findViewById(R.id.imgView);
iv.setBackgroundDrawable(context.getResources().getDrawable(i.img));
Run Code Online (Sandbox Code Playgroud)
我想我的参数类型有问题:"setBackgroundDrawable"需要一个drawable参数."getDrawable"需要一个int.我已将我的字段img的类型设置为int,但这不起作用.
知道为什么吗?
我的列表适配器:
public class adapter extends ArrayAdapter<ListItems> {
int resource;
String response;
Context context;
//Initialize adapter
public ListItemsAdapter(Context context, int resource, List<ListItems> items) {
super(context, resource, items);
this.resource=resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//Get the current object
ListItems i = getItem(position);
//Inflate the view
if(convertView==null)
{
ll = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li;
li = (LayoutInflater)getContext().getSystemService(inflater); …Run Code Online (Sandbox Code Playgroud) 我使用的是Xcode Version 6.1(6A1052d)
我想在模拟器上启动一个应用程序.
它第一次总能正常工作.如果我想第二次启动,我有一个错误(见下面的日志).然后在iOS模拟器中我"重置内容和设置",我可以再次成功启动.
鉴于错误日志,我认为它必须与错误的路径有关.问题是我对Mac文件系统和路径链接不好,所以非常感谢你的帮助.
编辑:这是info.plist.xml(如果重要的话由LibGDX生成)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${app.name}</string>
<key>CFBundleExecutable</key>
<string>${app.executable}</string>
<key>CFBundleIdentifier</key>
<string>${app.id}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${app.name}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${app.version}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${app.build}</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarHidden</key>
<true/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>opengles-2</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<!-- <string>UIInterfaceOrientationPortrait</string> -->
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>Icon</string>
<string>Icon-72</string>
</array>
</dict>
</dict>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
还有我的robovm.xml:
app.version=1.0 …Run Code Online (Sandbox Code Playgroud) 我正在使用 Hiero 生成的 BitmapFont。我遵循这个伟大的指南https://github.com/libgdx/libgdx/wiki/Distance-field-fonts来正确使用距离场。我还使用指南中提供的着色器。一切都很好。
在接近尾声时,指南中提到,除了距离场抗锯齿之外,还应该很容易从提供的着色器向字体添加轮廓。这与调整距离参数有关。我相信对于知道如何处理着色器的人来说这很容易。但我不这么认为。
这是碎片代码
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
varying vec4 v_color;
varying vec2 v_texCoord;
const float smoothing = 1.0/16.0;
void main() {
float distance = texture2D(u_texture, v_texCoord).a;
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
gl_FragColor = vec4(v_color.rgb, alpha);
}
Run Code Online (Sandbox Code Playgroud)
这是垂直代码:
uniform mat4 u_projTrans;
attribute vec4 a_position;
attribute vec2 a_texCoord0;
attribute vec4 a_color;
varying vec4 v_color;
varying vec2 v_texCoord;
void main() {
gl_Position = u_projTrans * a_position; …Run Code Online (Sandbox Code Playgroud) 我对Android代码的性能和最佳方法有疑问.
我需要做的是相当简单,我想动态地为字符串ressource分配一个文本值,具体取决于int参数:
现在我正在使用一个大开关盒
int messagesCategory;
if(extras !=null) {
messagesCategory = extras.getInt("category");
}
TextView titleText;
titleText = (TextView) findViewById(R.id.headerTitle);
switch (messagesCategory) {
case 1: titleText.setText(R.string.TitleMessageList1); break;
case 2: titleText.setText(R.string.TitleMessageList2); break;
case 3: titleText.setText(R.string.TitleMessageList3); break;
case 4: titleText.setText(R.string.TitleMessageList4); break;
case ...: titleText.setText(R.string.TitleMessageList...); break;
case n: titleText.setText(R.string.TitleMessageListn); break;
default: titleText.setText("a default title"); break;
}
Run Code Online (Sandbox Code Playgroud)
假设我在这个开关中有30行...它可以工作,但在很多情况下,它看起来有更好的方法来实现这一点.不幸的是,看起来不可能为R.string分配动态.
所以我的第一个问题是:1)性能明智,在这种情况下,使用大型开关30个左右是一个问题吗?2)什么应该是最好的方法?
谢谢,祝你有个美好的一天
我正在使用一个2维的String数组.当我启动它时,我用一个默认值String填充它.当我想从中访问元素时,我会超出范围错误
class MyClass: UIViewController, {
var bodies = [[String]]()
override func viewDidLoad() {
super.viewDidLoad()
setBodies()
if isBodiesEmpty() {
//setRefreshButton()
}
}
private func setBodies() {
var bodies = Array(repeating: Array(repeating: "default", count: 6), count: 4)
...
bodies[2][0] = "string 2 0"
bodies[2][1] = "string 2 1"
...
}
private func isBodiesEmpty() -> Bool {
if bodies[2][0].isEmpty {
return true
}
if bodies[2][0].contains("default"){
return true
}
return false
}
}
Run Code Online (Sandbox Code Playgroud)
都
if bodies[2][0].isEmpty
Run Code Online (Sandbox Code Playgroud)
和
if bodies[2][0].contains("default")
Run Code Online (Sandbox Code Playgroud)
抛出"线程1:致命错误:索引超出范围"
然而,如果我打印我的数组的元素,它的工作原理:
print("bodies[2][0] =="+bodies[2][0])
Run Code Online (Sandbox Code Playgroud)
显示:"string …