将数据从列表视图到另一个活动

将数据从列表视图到另一个活动

本文介绍了将数据从列表视图到另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个活动,在其中,我想有一个列表视图,也可以在列表视图中约20-30项,在攻在列表视图任何特定的值,就应该移动到另一个活动,与列表视图中的数据。

i want to create an activity, in which, i would like to have a listview, there can be about 20-30 items in a list view,on tapping any particular value in listview, it should move to another activity, with the data of list view.

从列表视图到另一个活动只是想传递数据。建议PLZ问候

Just wanna pass data from listview to another activity.Suggestion plzRegards

推荐答案

实施的ListView 的OnItemClickListener,一旦你处理此事件,试图让该行的位置被点击。

Implement ListView's OnItemClickListener, once you handle this event, try to get the location of the row that was clicked.

一旦你得到它,访问源阵列(或者其他任何你有),特别是行的位置。这样一来,你就必须要传递到另一个活动的数据。

Once you get it, access that particular row position in the source array (or whatever else you're having). This way, you'll have the data that you want to pass to another activity.

现在使用code:

Intent anotherActivityIntent = new Intent(this, AnotherActivity.class);
anotherActivityIntent.putExtra("my.package.dataToPass",dataFromClickedRow);
startActivity(anotherActivityIntent);

anotherActivityIntent 启动 AnotherActivity 类,使用下面的code访问的价值,你通过了:

and when the anotherActivityIntent starts the AnotherActivity class, use following code to access the value that you had passed:

Bundle recdData = getIntent().getExtras();
String myVal = recdData.getString("my.package.dataToPass");

现在你在设为myVal 可变数据。你可以使用任何其他数据类型,无论你喜欢。

Now you have your data in myVal variable. you can use any other data type, whichever you like.

这篇关于将数据从列表视图到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 20:56