transferring data from string arrays into another activity

Nick Fallows

I have a fragment with a recycler view and an adaptor that accesses my string arrays, so that they are shown in the recycler view. My question is how can I transfer the data held in these arrays to a new activity, so when the user clicks on the selected item it then brings up more information held in these arrays. I am not sure how it can be done, I have tried putting the values into an array list but can't seem to get it to work, as I am new to this. Thank you in advance

This is my fragment

public class EventCalenderFragment extends Fragment {

RecyclerView recyclerView;
EventCalenderAdapter adapter;


public EventCalenderFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    adapter = new EventCalenderAdapter(getActivity());

}



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_event_calender, container, false);
    recyclerView = (RecyclerView) v.findViewById(R.id.recycler);
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return v;
}


}

This is my adapter

public class EventCalenderAdapter extends RecyclerView.Adapter<EventCalenderAdapter.ViewHolder> {


String[] title;
String[] time_start;
String[] time_finish;
String[] date;
String[] description;
String[] loc_lat;
String[] loc_long;

static class ViewHolder extends RecyclerView.ViewHolder {
    CardView cardView;
    TextView titleView;
    TextView auxView1;

    public ViewHolder(CardView card) {
        super(card);
        cardView = card;
        titleView = (TextView) card.findViewById(R.id.text1);
        auxView1 = (TextView) card.findViewById(R.id.text2);
    }
}

public EventCalenderAdapter (Context context) {

    title = context.getResources().getStringArray(R.array.title);
    time_start = context.getResources().getStringArray(R.array.time_start);
    time_finish = context.getResources().getStringArray(R.array.time_finish);
    date = context.getResources().getStringArray(R.array.date);
    description = context.getResources().getStringArray(R.array.description);
    loc_lat = context.getResources().getStringArray(R.array.loc_lat);
    loc_long = context.getResources().getStringArray(R.array.loc_long);

}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
    CardView v = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.event_task, parent, false);
    return new ViewHolder(v);
}

@Override
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
    final Context context = viewHolder.titleView.getContext();
    viewHolder.titleView.setText(title[i]);
    viewHolder.auxView1.setText("Date: "+ date[i] + " Start: " + time_start[i] + " Finish: " + time_finish[i]);

    viewHolder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((OnEventView) context).eventView(i);
        }
    });

}
@Override
public int getItemCount() {
    return title.length;
}


}

and this is the fragment I would like to access the data

public class EventViewFragment extends Fragment {

public static final String DEFAULT_FRAGMENT_TAG = "eventViewFragment";
static final String EVENT_ID = "eventId";

View rootView;
TextView title;
TextView description;
TextView date_time;
TextView location;

long eventId;

public static EventViewFragment newInstance(long id) {
    EventViewFragment fragment = new EventViewFragment();
    Bundle args = new Bundle();
    args.putLong(EventViewActivity.VIEW_EVENTID, id);
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle arguments = getArguments();
    if (arguments != null) {
        eventId = arguments.getLong(EventViewActivity.VIEW_EVENTID, 0L);
    }
    if (savedInstanceState != null) {
        eventId = savedInstanceState.getLong(EVENT_ID);
    }
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putLong(EVENT_ID, eventId);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_event_view, container, false);
    rootView = v.getRootView();
    title = (TextView) v.findViewById(R.id.title);
    description = (TextView) v.findViewById(R.id.description);
    date_time = (TextView) v.findViewById(R.id.time_date);
    location =  (TextView) v.findViewById(R.id.location);

    date_time.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    location.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    return v;
}
}
Nagaraju V

Once try as follows In the first activity

Intent i=new Intent(getActivity(),NextActivity.class);
 i.putStringArrayListExtra("title", (ArrayList) Arrays.asList(title));
 i.putStringArrayListExtra("time_start",(ArrayList)Arrays.asList(time_start));
  i.putStringArrayListExtra("time_finish",(ArrayList)Arrays.asList(time_finish));
    i.putStringArrayListExtra("date",(ArrayList)Arrays.asList(date));
    i.putStringArrayListExtra("description",(ArrayList)Arrays.asList(description));
    i.putStringArrayListExtra("loc_lat",(ArrayList)Arrays.asList(loc_lat));
    i.putStringArrayListExtra("loc_long",(ArrayList)Arrays.asList(loc_long));

And in the next activity

 List<String> title1=getIntent().getStringArrayListExtra("title");
 ........................................

..........................................

Hope this will helps you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Transferring data from int to string

From Dev

Transferring data from one view to another in Rails

From Dev

Transferring data from one page to another windows 8 phone app

From Dev

Transferring 70TB data from one remote server to another

From Dev

Best practice transferring list data from controller to the another controller

From Dev

Transferring data from one table to another using a where clause mysql

From Dev

Transferring arrays from c to python

From Java

Pass data from Activity to Fragment in another Activity

From Dev

To get data from another activity

From Dev

VBA transferring data to another workbook

From Dev

Android: transferring Context and activity from a fragment to a class

From Dev

Transferring data from postgres to rabbitmq

From Dev

Pass String[] from one activity to another

From Dev

How to send string from one activity to another?

From Dev

copy string from activity to another Android

From Dev

Pass String[] from one activity to another

From Dev

Passing a string from one activity to another

From Dev

Get text from EditText into string to another activity

From Dev

how to return string from AsyncTask to another activity

From Dev

Return a String from AsyncTask to use in another Activity?

From Dev

When transferring a piece of data from one hard drive to another, where is the intermittent data stored?

From Dev

Sending data from one activity to another startactivityforresult

From Dev

Passing data from one activity to another and then printing

From Dev

How to retrieve data in spinner from another activity?

From Dev

Notifying data change from one activity to another

From Dev

Get HashMap data from another Activity

From Dev

Sending data from one activity to another startactivityforresult

From Dev

Calling activity from another app that stores data

From Dev

Transfer data from one activity to another

Related Related

  1. 1

    Transferring data from int to string

  2. 2

    Transferring data from one view to another in Rails

  3. 3

    Transferring data from one page to another windows 8 phone app

  4. 4

    Transferring 70TB data from one remote server to another

  5. 5

    Best practice transferring list data from controller to the another controller

  6. 6

    Transferring data from one table to another using a where clause mysql

  7. 7

    Transferring arrays from c to python

  8. 8

    Pass data from Activity to Fragment in another Activity

  9. 9

    To get data from another activity

  10. 10

    VBA transferring data to another workbook

  11. 11

    Android: transferring Context and activity from a fragment to a class

  12. 12

    Transferring data from postgres to rabbitmq

  13. 13

    Pass String[] from one activity to another

  14. 14

    How to send string from one activity to another?

  15. 15

    copy string from activity to another Android

  16. 16

    Pass String[] from one activity to another

  17. 17

    Passing a string from one activity to another

  18. 18

    Get text from EditText into string to another activity

  19. 19

    how to return string from AsyncTask to another activity

  20. 20

    Return a String from AsyncTask to use in another Activity?

  21. 21

    When transferring a piece of data from one hard drive to another, where is the intermittent data stored?

  22. 22

    Sending data from one activity to another startactivityforresult

  23. 23

    Passing data from one activity to another and then printing

  24. 24

    How to retrieve data in spinner from another activity?

  25. 25

    Notifying data change from one activity to another

  26. 26

    Get HashMap data from another Activity

  27. 27

    Sending data from one activity to another startactivityforresult

  28. 28

    Calling activity from another app that stores data

  29. 29

    Transfer data from one activity to another

HotTag

Archive