小编Dan*_*Dan的帖子

ArrayIndexOutOfBoundsException,包含用于ListView中多个视图的自定义Android适配器

我正在尝试为ListView创建自定义适配器,因为列表中的每个项目都可以有不同的视图(链接,切换或无线电组),但是当我尝试运行使用ListView的Activity时,我收到错误,该应用程序停止.该应用程序针对Android 1.6平台.

代码:

public class MenuListAdapter extends BaseAdapter {
 private static final String LOG_KEY = MenuListAdapter.class.getSimpleName();

 protected List<MenuItem> list;
 protected Context ctx;
 protected LayoutInflater inflater;

 public MenuListAdapter(Context context, List<MenuItem> objects) {
  this.list = objects;
  this.ctx = context;
  this.inflater = (LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 }

 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  Log.i(LOG_KEY, "Position: " + position + "; convertView = " + convertView + "; parent=" + parent);
  MenuItem item = list.get(position);
  Log.i(LOG_KEY, "Item=" + item );

        if (convertView == …
Run Code Online (Sandbox Code Playgroud)

android listview exception adapter

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

用于Hudson摄取的Android InstrumentationTestRunner XML输出

我有一个Android测试项目,我想链接到Hudson,但我没有找到一种方法将测试结果输出为XML而不是文本.有谁知道有没有一种简单的方法可以做到这一点?

-担

xml instrumentation android

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

Android动画XML问题

我正在尝试使用Android的动画框架让我的ImageView以菱形图案移动.这是我的animation.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
<translate 
    android:fromXDelta="40%p" android:toXDelta="90%p" 
    android:fromYDelta="10%p" android:toYDelta="40%p" 
    android:duration="500" android:startOffset="0"/>
<translate 
    android:fromXDelta="90%p" android:toXDelta="40%p" 
    android:fromYDelta="40%p" android:toYDelta="90%p" 
    android:duration="500" android:startOffset="500"/>
<translate 
    android:fromXDelta="40%p" android:toXDelta="10%p" 
    android:fromYDelta="90%p" android:toYDelta="40%p" 
    android:duration="500" android:startOffset="1000"/>
<translate 
    android:fromXDelta="10%p" android:toXDelta="40%p" 
    android:fromYDelta="40%p" android:toYDelta="10%p" 
    android:duration="500" android:startOffset="1500"/>
</set>
Run Code Online (Sandbox Code Playgroud)

我的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
    <ImageView
        android:id="@+id/img"  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:src="@drawable/icon"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

我的onStart:

protected void onStart() {
    super.onStart();

    ImageView img = (ImageView)findViewById(R.id.img);
    Animation a = AnimationUtils.loadAnimation(this, R.anim.diamond);
    img.startAnimation(a);
}
Run Code Online (Sandbox Code Playgroud)

当我启动我的应用程序时,我看到的是一个空白屏幕2秒然后我的图像弹出到屏幕的左上角.如果我删除除了一个翻译动画之外的所有动画,我会看到图像以对角线移动.

我更喜欢使用XML来定义动画而不是Java.

有没有人对我如何看到整个动画有任何见解?

-担

animation android

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

令人困惑的PNG绑定解决方案

我遇到了关于PNG文件绑定的问题.深入研究这个问题已经产生了两个解决方案.两者都是有意义的,但他们并没有.我发现的解决方案:

1)将PNG文件移动到"原始"文件夹中.这可以防止AAPT"优化"图像,从而导致条带化.

2)将Activity的窗口的像素格式更改为RGBA_8888(即在onCreate中添加此行"getWindow().setFormat(PixelFormat.RGBA_8888)").在Android 2.2及更低版本中,默认像素格式为16位(565).

我已经尝试了这两个并且它们在我的图像中纠正了条带效果,但是现在我对Android正在做的事情更加困惑.

一方面,如果我将PNG留在可绘制文件夹中,它将被"优化",从而在图像中产生条带效果.当我将像素格式更改为32位时,它会神奇地消失.如果图像是"优化的",我会期望保留条带.

另一方面,如果我将PNG移动到原始文件夹,它将保留漂亮的渐变并显示良好,即使pixelFormat应该是16位.

如果有人对正在发生的事情有任何了解,我将不胜感激.

谢谢,

-担

png android

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

在RestEasy中从ExceptionMapper返回JSON的简单方法?

情况如下:

  1. 我有RESTEasy和杰克逊一起工作
  2. 我的RESTful类实现了ExceptionMapper,并在它们上面有一个toResponse方法.
  3. 如果我的任何RESTful方法中存在问题,则会抛出异常并由toResponse方法捕获.
  4. 我想将异常变成格式良好的XML或JSON(取决于Accept标头)

问题是我不知道toResponse方法中的Accept标头是什么.我知道我可以扩展Exception类并将头文件作为变量传递,然后我可以在toResponse中使用它,但我希望有一种更"正确"的方法来做到这一点.我试过将@Produces注释添加到toResponse方法但没有成功.

有没有人成功配置RESTEasy以轻松地从toResponse返回JSON或XML?

-担

xml json exception resteasy

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

Java和crossdomain.xml

有没有人有Java从其他域提取数据的经验?假设我的客户至少有1.6.0_10,它的工作能力有多大.我看过一些帖子说它有效,然后其他人说它没有,还有一些人说它在后来的微更新中被打破了.任何见解将不胜感激.

谢谢,

-担

java applet crossdomain.xml

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

有没有办法在JAXB中配置渲染深度?

假设我的域对象已经布局,所以XML看起来像这样:

<account id="1">
  <name>Dan</name>
  <friends>
    <friend id="2">
      <name>RJ</name>
    </friend>
    <friend id="3">
      <name>George</name>
    </friend>
  </friends>
</account>
Run Code Online (Sandbox Code Playgroud)

我的域名对象:

@XmlRootElement
public class Account {
    @XmlAttribute
    public Long id;
    public String name;

    @XmlElementWrapper(name = "friends")
    @XmlElement(name = "friend")
    public List<Account> friends;
}
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以将JAXB配置为仅渲染到2的深度?意思是,我希望我的XML看起来像这样:

<account id="1">
    <name>Dan</name>
    <friends>
        <friend id="2" />
        <friend id="3" />
    </friends>
</account>
Run Code Online (Sandbox Code Playgroud)

java xml jaxb

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