访问列表视图项目字符串的最简单方法是什么?

What's the easiest way to access listview item string?

我有一个列表视图,我想在单击该列表视图中的项目时启动一个新的 activity。如何从新 activity?

访问该项目的变量

编辑:我的列表视图是通过 Asynctask 和 RSS Feed 填充的。我想访问数组中的一项并读出它的 url.

方法一:

您可以在单击列表视图时将其存储在自定义 class(实现 Serilizable)的对象中,并通过 intent 传递该对象。确保:

  //to pass :
  intent.putExtra("MyClass", obj);  

 // to retrieve object in second Activity
getIntent().getSerializableExtra("MyClass");

方法二(不推荐):

创建静态自定义 class 并将 onclick 中的变量存储到该 class 实例。

对于静态 Class A {...}

//To pass
A.variable = "stored value";

//retrieve
 String s = A.variable;

方法三

使用 SharePreferences。仅当您需要记住用户上次使用该应用时点击的内容时才推荐使用。