English 中文(简体)
何时应该让项目位置考虑改变项目位置?
原标题:When should getItemPosition consider changes of an item s position?

方法的文档在Android s PagerAdapter 类中获取项目位置时指出:

当主机视图试图确定某个项目的位置是否已经改变时调用 。

使用该方法应表明该适配器在一组项目中某一项的位置是否已经改变。

但是,它从来没有说明一个压倒一切的方法应该何时考虑要改变的位置。 它是否意味着位置与上次项目被调用时的位置不同? 它是否意味着项目的位置不同于上次通知DataSetChanged时的位置? 还是它意味着项目的位置不同于在将项目添加到查看器时的位置?

最佳回答

您可以在 ViewPager.java 中看到, getTroundTholePposition 只在 dataSet Changed 中被调用。 这意味着如果项目的位置与上次调用 dataSetChanged 时不同, 则会改变 。

我不担心“改变”的含义,

  1. The position of the added items never changes, then getItemPosition returns POSITION_UNCHANGED;
  2. The position of the items changes, or items are removed. If the item position did not change, there is no difference if you return POSITION_UNCHANGED or the actual position. So to keep the implementation simple you can return the position (or POSITION_NONE) and forget about POSITION_UNCHANGED..
问题回答

默认情况下, ViewPager 中的项目位置被视为已固定; 这就是为什么 getTroupPostisition () 以默认返回 POSItion_UNCHANGED 。 当您在周围移动一个项目时, ViewPager 必须知道要在哪里删除一个项目( 该项目的旧位置), 在哪里添加它。 这是使用 getTroupPosimtion () 的功能。 它允许您告诉 ViewPager 将哪个项目放置在哪里, 即使您的页面已被即时化 。

getTroundPostposition () 只有当您在您的 PagerAdapter 调用 通知 DataSetChanged () 时才被调用。 其设计意指“ 更改” 意指“ 更改时, 当 ViewPager 上次将页面填入时 ”, 即为 通知DataSetChanged () 导致 ViewPager 必要时对其子子重写 。 换句话说:“ 更改” 有您所提到的任何含义; 最近的是哪一个 。

我认为 get Troup Poposition 没有样本就很难理解。 getTroupposition(...) 的例子,这里 ;我想这将澄清一些事情。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签