ListView控件没有在Android 1.5检查项目 [英] ListView not checking items on Android 1.5

查看:103
本文介绍了ListView控件没有在Android 1.5检查项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发在Eclipse为Android的应用程序。目前,我的目标API级别为3,但我错误地在Android 1.6模拟器(API等级4)测试。在1.6它工作得很好,但在我的1.5与CHOICE_MODE_SINGLE的ListView被点击时,他们并不选择项目。

I'm developing an app for Android in Eclipse. Currently I target API level 3, but I was mistakenly testing on an Android 1.6 emulator (API level 4). On 1.6 it worked fine, but on 1.5 my ListView with CHOICE_MODE_SINGLE does not select items when they are clicked on.

下面是我的ListView XML:

Here's my listview XML:

<ListView 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    android:id="@+id/ListDomains" 
    android:layout_margin="5px" 
    android:choiceMode="singleChoice" 
    android:clickable="false"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:descendantFocusability="beforeDescendants"
>
</ListView>

下面是在列表视图中项目的XML:

Here's the XML for the items in the listview:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" 
    android:id="@+id/domain_list_value"
    android:checkMark="?android:attr/listChoiceIndicatorSingle" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_width="fill_parent" 
>
</CheckedTextView>

我创建一个自定义的ArrayList适配器,让我定制getView。这里的code为DomainArrayAdapter:

I created a custom ArrayList adapter to let me customize getView. Here's the code for DomainArrayAdapter:

public class DomainArrayAdapter extends ArrayAdapter<char[]> {

    private LayoutInflater mInflater;

    public DomainArrayAdapter(Context context, int textViewResourceId,
            List<char[]> objects) {     
        super(context, textViewResourceId, objects);    
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = mInflater.inflate(R.layout.domain_list, null);
        }

        char[] text = super.getItem(position);

        ((CheckedTextView)convertView).setText(text, 0, text.length);
        return convertView;
    }

}

这一切code的工作正常编译对API级别3和在Android 1.6模拟器中运行。但是,对一个1.5模拟器中运行,在ListView项目不点击时确认。

All of this code works fine compiled against API level 3 and run on an Android 1.6 emulator. However, run against a 1.5 emulator, items in the ListView do not check when clicked on.

任何想法?

推荐答案

看来Android 1.5的不尊重choiceMode在ListView XML设置。它设置编程使其正常工作:

It appears Android 1.5 does not respect the choiceMode set in the listview XML. Setting it programatically causes it to work correctly:

    ListView listDomains = (ListView) findViewById(R.id.ListDomains);

    Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 0

    listDomains.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 1

有其他人看到这种行为?

Has anyone else seen this sort of behavior?

这篇关于ListView控件没有在Android 1.5检查项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆