即时得到-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.
更多推荐
安卓:列表视图中选择项目
发布评论