Android 如何从fragment启动另一个活动,并将所选的成员信息放入extras?

Android 如何从fragment启动另一个活动,并将所选的成员信息放入extras?,android,android-intent,android-fragments,Android,Android Intent,Android Fragments,这是第一个包含片段activity_fpage.xml的页面 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom

这是第一个包含片段activity_fpage.xml的页面

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<ImageView
    android:id="@+id/gymView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/arnold"
    android:layout_centerHorizontal="true"
    android:contentDescription="@string/appIcon"
    android:src="@drawable/ic_launcher" />

<Button
    android:id="@+id/newUser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/arnold"
    android:layout_centerHorizontal="true"
    android:minWidth="288dip"
    android:text="@string/newUser" />

<fragment
    android:id="@+id/fragmet_user_list"
    android:name="com.example.gym1_1.ListOfUsers"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/newUser" />
问题是如何让Matt,Ken,July,Trish可点击,通过点击哪个用户将被发送到下一个活动,并将点击的名称放入额外内容?
谢谢

您必须重写该方法

public void onListItemClick (ListView l, View v, int position, long id)
然后,使用位置,从数组中获取choosen名称,然后将其传递给intent。比如:

 @Override
 public void onListItemClick (ListView l, View v, int position, long id){
     Intent intent = new Intent(getActivity(),com.example.gym1_1.MainActivity.class);
     intent.putExtra("name", data[position]);
     startActivity(intent);
 }

好吧,在这样的作文中,意图不起作用,另一个答案是正确的,但是感谢大家的关注。请解释,如果唯一的区别是意图的价值来源,那么与公认的答案相比,意图怎么可能不起作用。putExtra?我在这里看到的唯一问题是,您不知道如何从名称选择器中获取所选的值,并将其作为chosenName传递。事实上,你可以从视图中得到。你误解了,或者我解释得不太好。当我启动此处显示的代码时,列表中的按钮不会带我进入下一个活动。Renan建议重写另一种方法public void onListItemClick
@Override
public void onClick(View v) {
    Intent intent = new Intent(getActivity(),com.example.gym1_1.MainActivity.class);
intent.putExtra("name_key",chosenName); // get the chosenName as a String from your widget with names
    startActivity(intent);
}
public void onListItemClick (ListView l, View v, int position, long id)
 @Override
 public void onListItemClick (ListView l, View v, int position, long id){
     Intent intent = new Intent(getActivity(),com.example.gym1_1.MainActivity.class);
     intent.putExtra("name", data[position]);
     startActivity(intent);
 }