如何设置重点列表视图项? [英] How to set focus in listview item?

查看:92
本文介绍了如何设置重点列表视图项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不将焦点设置ListView项。 ListView控件组成的TextView的。
地步,我想将焦点设置ListView项,在这一点上我有该项目的位置。

我曾尝试setSelectio(POS),其中pos是ListView项的位置,但这会导致在屏幕上方设置项目的位置在位置。

请建议我应该怎么办。

  builder.setPositiveButton(R.string.save,
                新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话,诠释的id){
                        Log.d(@拉夫,changeText不为空);                        如果(NULL!= changeText){
                            Log.d(@拉夫,changeText不为空);
                            如果(!(changeText.getText()。的toString()。equalsIgnoreCase())){
                                myList中
                                        .SET(POS,changeText.getText()
                                                的ToString());
                                adapter.notifyDataSetChanged();
                                setListAdapter(适配器);
                            }
                        }其他{
                            Log.d(@拉夫,changeText为空);
                        }
                        。getListView()setFocusableInTouchMode(真);
                        。getListView()setSelection(POS)
                        。getListView()requestFocus()方法;
                    }                });


解决方案

我想你想突出根据您的需要特定的列表项。所以,你如果该项目不在屏幕上可见无法进行对焦。我对吗 ?如果这是你的问题,你可以用下面的方法公共无效smoothScrollToPosition(INT位置)
在API级别8
滚动到特定的位置,然后用setSelection()方法

I have to set focus on listview item. ListView consist of TextView. point where i want to set focus on listview item, at that point i have the position of that item.

I have tried setSelectio(pos), where pos is the position of listview item, but this results in setting the position of item at position on the top of the screen.

please suggest me how to proceed.

   builder.setPositiveButton(R.string.save,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Log.d("@gaurav", "changeText is not null");

                        if (null != changeText) {
                            Log.d("@gaurav", "changeText is not null");
                            if (!(changeText.getText().toString().equalsIgnoreCase(""))) {
                                myList
                                        .set(pos, changeText.getText()
                                                .toString());
                                adapter.notifyDataSetChanged();
                                setListAdapter(adapter);
                            }
                        } else {
                            Log.d("@gaurav", "changeText is null");
                        }
                        getListView().setFocusableInTouchMode(true);
                        getListView().setSelection(pos);
                        getListView().requestFocus();
                    }

                });

解决方案

I think you want to highlight a particular list item based on your requirement. So you are not able to set the focus if the item is not visible in the screen. Am I right ? If that is your problem you can use following method public void smoothScrollToPosition (int position) Added in API level 8 to scroll to that particular position and then use setSelection() method

这篇关于如何设置重点列表视图项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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