English 中文(简体)
抵达 项目5
原标题:getItem vs. getItemAtPosition

There are 2 ways of getting selected Item of a list view.

  1. list.getAdapter().getItem(position);
  2. list.getItemAtPosition(position)

My question is, which one is the preferred way of doing it?

我看到有人使用这两种方法。

最佳回答

你可以使用你想要的东西。 <代码>getItemAtPosition(position),基本上向适应者发出getItem(position)的呼吁。

问题回答

此处是<代码> > 源代码 。 清单

public Object getItemAtPosition(int position) {
  T adapter = getAdapter();
  return (adapter == null || position < 0) ? null : adapter.getItem(position);
}

因此,基本情况相同。

另一种答案是不正确的,有一大差别。

当你在一份清单中添加一个标题时,名单就把改编者列入一个标题ListAdapter。 HeaderViewListAdapter s work is translation position to take the Headers into account.

例如,如果您增加了一个标题<代码>,<> > > > > > 即为背后改编者<代码>0。 如果你试图使用适应器,那么实际上会把第二个项目归还给适应者。

如果你添加了一张头盔,你必须使用清单。





相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签