-1

I am making one Android Application and I am Stuck at One Point and need help for it.

I have the List Of Doctors. each list row contains only DoctorName and Speciality.

I want to show each Doctors Information Like his Address,Phone number etc.on its ItemClick in new Layout.

How to Pass this two Parameters(DocName,Speciality) through onItemClickListner() according to Position using Intent to Open my New Activity(DoctorInfo)

How to retrive that text value of DoctorName of each row which i Select using setOnItemClickListner()

how to resolve it???

this is my listner method

lstDoctorList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
           @Override
           public void onItemClick(AdapterView<?> parent, View view, int                position, long id) {
                String DocName = view.findViewById(R.id.txtDoctorName).;// I want Solution for this Line
               Intent i = new Intent(DoctorsActivity.this,DoctorInfo.class);
               i.putExtra("DocName",DocName);
               startActivity(i);
           }
       });

How I will get DoctorName to Pass my New Activity???

Pranita
  • 803
  • 7
  • 16

2 Answers2

0

This is how you pass data from one activity to another activity :

ListView listView = getListView();

            // listening to single list item on click
            listView.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view,
                  int position, long id) {

                  // selected item
                HERE YOU GOT POSITION FOR PARTICULAR ITEM

                  // Launching new Activity on selecting single List Item
               Intent intent = new Intent(getBaseContext(),       ActivityToLaunch.class);
                 intent.putExtra("DOCTOR_NAME", here get the doctor name from your list using the position arg);
                 startActivity(intent);

              }
            });`

And in ActivityToLaunch

Intent intent = getIntent(); String getDoctorName = intent.getStringExtra("DOCTOR_NAME");

Damini Mehra
  • 3,257
  • 3
  • 13
  • 24
Vivek_Neel
  • 1,343
  • 1
  • 14
  • 25
0

in your setOnItemClickListener()

Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("Doctorname", DocName);
startActivity(intent);

get intent in your second activity:

  Intent intent = getIntent();
  String dn = intent.getStringExtra("Doctorname");
Damini Mehra
  • 3,257
  • 3
  • 13
  • 24