如何触发onListItemClick在ListFragment [英] How to trigger onListItemClick in a ListFragment

查看:103
本文介绍了如何触发onListItemClick在ListFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的平板电脑的布局,我有三个ListFragments和一个常规片段,让我们称他们为品牌,型号,规格,和详细信息。最初,使列表填充,然后根据进行选择,型号列表中填充;当选择了型号,大小列表填充;当选择了尺寸,细节示。每个事件(列表项选择)是通过onListItemClick处理程序处理。

In the tablet layout of my app, I have three ListFragments and one regular Fragment, let's call them Make, Model, Size, and Details. Initially the Make list is populated, then based on the Make selection, the Model list is populated; when a Model is selected, the Size list is populated; when a Size is selected, Details are shown. Each of these events (list item selection) is handled through the onListItemClick handler.

在启动时,我想填充使列表,在列表中选择第一个制作并让它经过onListItemClick处理程序来填充模型列表(等等,使所有列表填充和细节都显示 - 这也应该是任何时候做出选择在任何名单的行为 - 在接下来的列表中选择第一项,直到我们得到显示详细信息)。请注意,我有DB的控制,并为每一位制作总是会有至少一个模型,每个品牌/型号至少有一个尺寸,每个品牌/型号/规格只有一个细节。

On startup, I want to populate the Make list, select the first Make in the list and have it go through the onListItemClick handler to populate the Model list (and so on so that all lists are populated and the details are shown - this should also be the behavior when any selection is made in any of the lists - select the first item in the next list until we get to showing the details). Note that I have control of the DB and for every Make there will always be at least one Model, for each Make/Model at least one Size, for each Make/Model/Size exactly one Detail.

所以,我想在列表中选择第一项,并将它触发onListItemClick处理。我已经试过以下(在适当的边界检查等),但它不能正常工作。

So, I want to select the first item in the list and have it trigger the onListItemClick handler. I've tried the following (with appropriate bounds checking, etc), but it doesn't work.

getListView().setItemChecked(0, true);

的唯一更改为开箱即用的ListFragment是设置CacheColorHint这样

The only changes to an "out of the box" ListFragment are to set the CacheColorHint as such

getListView().setCacheColorHint(R.color.GhostWhite);

在这里GhostWhite是在styles.xml设置为

where GhostWhite is set in the styles.xml as

<color name="GhostWhite">#88FFFFFF</color>

任何想法?

在此先感谢。

推荐答案

要选择第一项在列表中,首先获得焦点的接触,然后选择第一项,然后触发onclick处理程序

To select the first item in the list, first get focus from touch, then select the first item, then trigger the onclick handler

int position = 0;
getListView().requestFocusFromTouch();
getListView().setSelection(position);
getListView().performItemClick(getListView().getAdapter().getView(position, null, null), position, position);

这篇关于如何触发onListItemClick在ListFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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