安卓:列表视图中选择项目

编程入门 行业动态 更新时间:2024-10-19 20:24:41
本文介绍了安卓:列表视图中选择项目-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

即时得到-1值时,我试图让我的列表视图已填充已选定的项目位置。

Im getting a -1 value when i try to get the selected item position on my listview that is already populated.

list.setOnItemClickListener ( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView adapterView, View view,int arg2, long arg3) { int selectedPosition = adapterView.getSelectedItemPosition(); ShowAlert(String.valueOf(selectedPosition)); } } );

要填补我的列表视图我用下面的code:

To fill my list view i use the following code:

SimpleAdapter mSchedule = new SimpleAdapter( this, mylist, R.layout.listviewtest, new String[] {"test1", "test2", "test3"}, new int[] {R.id.TextView_websitename, R.id.TextView_keywords, R.id.TextView_backlink});

你知道吗?

在此先感谢。

最好的问候。

何塞。

推荐答案

这意味着没有选择的行。该documentation指出 getSelectedItemPosition()返回:

That means there is no row selected. The documentation states that getSelectedItemPosition() returns:

INT位置(从0开始),或   INVALID_POSITION如果没有什么   选中。

int Position (starting at 0), or INVALID_POSITION if there is nothing selected.

和 INVALID_POSITION 是-1.

请注意,您所呼叫 getSelectedItemPosition()从 OnClickListener 。单击并选择没有必然关系。选择来自使用方向键或轨迹球导航列表内容。如果用户点击屏幕上(或者点击了仿真器),就没有选择了,但还是会有一个click事件。

Note that you are calling getSelectedItemPosition() from an OnClickListener. Click and selection are not necessarily related. Selection comes from using the D-pad or trackball to navigate the list contents. If the user taps on the screen (or clicks in the emulator), there will be no selection anymore, but there will still be a click event.

在 ARG2 值你展示的是位置被点击后,在列表中的项目。

The arg2 value you show is the position of the clicked-upon item in the list.

更多推荐

安卓:列表视图中选择项目

本文发布于:2023-11-10 22:20:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   项目   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!