I want to send the se_id and se_name of the selected item of the listview to another activity. I've retrieved the se_id and se_name from the database but it will only display the se_name in the list. If a user selects a name from the list, it will take the user to another activity where the se_id and se_name of the selected item should be sent. This is my SEList.class and I'll be sending the se_id and se_name in ChooseOptionSE.class. How do I send it using intent? Please reply as soon as possible. Thanks in advance.
package com.example.user.entapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class SEList extends AppCompatActivity {
int sup_id, val;
String s1, msg, se_id, se_name;
ListView list;
ArrayList<String> arrayList = new ArrayList<>();
ArrayAdapter<String> arrayAdapter;
JSONParser jsonParser=new JSONParser();
JSONArray pro;
URL url = new URL();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selist);
sup_id=getIntent().getExtras().getInt("sup_id");
list= (ListView) findViewById(R.id.list_se);
new DataReceive().execute();
}
public class DataReceive extends AsyncTask<String, String, String> {
ProgressDialog progressDialog = new ProgressDialog(SEList.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
try{
List<NameValuePair> pairlist = new ArrayList<NameValuePair>();
s1=Integer.toString(sup_id);
pairlist.add(new BasicNameValuePair("supervisor_id", s1));
JSONObject jsonObject=jsonParser.makeHttpRequest(url.RECEIVE_SENAME,"POST",pairlist);
val=jsonObject.getInt("val");
msg=jsonObject.getString("msg");
//id1=jsonObject.getInt("id");
pro=jsonObject.getJSONArray("information");
for(int i=0; i<pro.length(); i++) {
JSONObject jo = pro.getJSONObject(i);
se_id = jo.getString("se_id");
se_name = jo.getString("se_name");
arrayList.add(se_name);
}
}catch (Exception e){
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
if(val==1){
Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_SHORT).show();
arrayAdapter=new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,arrayList);
list.setAdapter(arrayAdapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String se = (String) parent.getItemAtPosition(position);
Intent intent = new Intent(SEList.this, ChooseOptionSE.class);
intent.putExtra("se_id",se_id);
startActivity(intent);
}
});
}
else{
Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_SHORT).show();
}
}
}
}