Android的,SpannableString,ArrayAdapter和ListView [英] Android, SpannableString, ArrayAdapter and Listview

查看:187
本文介绍了Android的,SpannableString,ArrayAdapter和ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,Android和我有一个问题要问你。我要图标添加到在ListView文本。我添加的行(TextView的),以低于code动态的ListView。但文字犯规包含的图标。

i am newbie to android and i got a question for you. I want to add icon to a text in a listview. I'm adding the rows(textview) to listview dynamically with below code. But the text doesnt contain the icon.

.
.
.
btnicon = (Button)findViewById(R.id.button1);
txt = (TextView)findViewById(R.id.textView1);
txt.setText("   denemedene",BufferType.SPANNABLE);
list = (ListView)findViewById(R.id.listview);
dizi = new ArrayAdapter<String>(this, R.layout.text);
list.setAdapter(dizi);
btnicon.setOnClickListener(click);
.
.
.
private OnClickListener click = new OnClickListener() {

    @Override
    public void onClick(View v) {
        if (v == btnicon){
            SpannableString spans = new SpannableString(txt.getText());
            Drawable dra = getResources().getDrawable(R.drawable.p1);
            dra.setBounds(0, 0, dra.getIntrinsicWidth() , dra.getIntrinsicHeight());
            ImageSpan span = new ImageSpan(dra,ImageSpan.ALIGN_BASELINE);
            spans.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            dizi.add(spans.toString());
        }
    }
};

这是一些关于toString方法。因为当我更改

it is something about the toString method. Because when i change the

dizi.add(spans.toString());

与行

txt.setText(spans,BufferType.SPANNABLE);

它的作品,我可以看到文本的图标。我不知道为什么它不与toString()方法的工作。

it works, i can see the icon on text. I have no idea why it is not working with toString() method.

任何想法?

谢谢..

推荐答案

有是在这篇文章中自定义列表适配器一个例子:<一href=\"http://stackoverflow.com/a/15272092/1752867\">http://stackoverflow.com/a/15272092/1752867

There is an example for custom list adapter in this post: http://stackoverflow.com/a/15272092/1752867

您可以创建自定义适配器这样的,在布局改变CheckBox组件使用的ImageView或进度

You can create your custom adapter like that and change checkbox component with imageView or ProgressBar in the layout

这篇关于Android的,SpannableString,ArrayAdapter和ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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