Boa noite, estou fazendo meu TCC e estou tendo dificuldades em retirar o ID de algum usuário da ListView e usá-lo em outra Activity (A intenção é que quando o usuário segurar o clique em cima de alguém da lista, apareça uma popup (popAdd) perguntando se ele deseja enviar uma solicitação de amizade para essa pessoa (E pra isso eu preciso de saber o ID da pessoa escolhida) popAddAmigo.java public class popAddAmigo extends Activity { String urlAddress="http://192.168.1.107/line/Pesquisa.php"; // String urlAddress="http://172.16.2.15/line/Pesquisa.php"; SearchView sv; ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.popaddamigo); lv = (ListView) findViewById(R.id.listaAmigos); sv = (SearchView) findViewById(R.id.svPesquisa); sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { SenderReceiver sr = new SenderReceiver(popAddAmigo.this, urlAddress, query, lv); sr.execute(); return false; } @Override public boolean onQueryTextChange(String query) { SenderReceiver sr = new SenderReceiver(popAddAmigo.this, urlAddress, query, lv); sr.execute(); return false; } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int pos, long id) { Intent abreAdd = new Intent(popAddAmigo.this, popAdd.class); startActivity(abreAdd); return false; } }); } } Parser.java public class SenderReceiver extends AsyncTask<Void,Void,String> { Context c; String urlAddress; String query; ListView lv; ProgressDialog pd; public SenderReceiver(Context c, String urlAddress, String query, ListView lv,ImageView...imageViews) { this.c = c; this.urlAddress = urlAddress; this.query = query; this.lv = lv; } @Override protected void onPreExecute() { super.onPreExecute(); pd=new ProgressDialog(c); pd.setTitle("Pesquisando..."); pd.setMessage("Por favor aguarde."); pd.show(); } @Override protected String doInBackground(Void... params) { return this.sendAndReceive(); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); pd.dismiss(); lv.setAdapter(null); if(s != null) { if(!s.contains("null")) { Parser p = new Parser(c,s,lv); p.execute(); Toast.makeText(c.getApplicationContext(), "Nada encontrado.", Toast.LENGTH_LONG).show(); } else { Toast.makeText(c.getApplicationContext(), "Usuário não existte.", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(c.getApplicationContext(), "Nenhuma conexão com a Internet foi encontrada.", Toast.LENGTH_LONG).show(); } } private String sendAndReceive() { HttpURLConnection con = Connector.connect(urlAddress); if(con==null) { return null; } try { OutputStream os = con.getOutputStream(); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os)); bw.write(new DataPackager(query).packageData()); bw.flush(); bw.close(); os.close(); int responseCode = con.getResponseCode(); if(responseCode==con.HTTP_OK) { InputStream is = con.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); if(br != null) { while ((line=br.readLine()) != null) { response.append(line+"n"); } } else { return null; } return response.toString(); } else { return String.valueOf(responseCode); } } catch (IOException e) { e.printStackTrace(); } return null; } } SenderReceiver.java public class SenderReceiver extends AsyncTask<Void,Void,String> { Context c; String urlAddress; String query; ListView lv; ProgressDialog pd; public SenderReceiver(Context c, String urlAddress, String query, ListView lv,ImageView...imageViews) { this.c = c; this.urlAddress = urlAddress; this.query = query; this.lv = lv; } @Override protected void onPreExecute() { super.onPreExecute(); pd=new ProgressDialog(c); pd.setTitle("Pesquisando..."); pd.setMessage("Por favor aguarde."); pd.show(); } @Override protected String doInBackground(Void... params) { return this.sendAndReceive(); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); pd.dismiss(); lv.setAdapter(null); if(s != null) { if(!s.contains("null")) { Parser p = new Parser(c,s,lv); p.execute(); } else { Toast.makeText(c.getApplicationContext(), "Usuário não encontrado.", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(c.getApplicationContext(), "Nenhuma conexão com a Internet foi encontrada.", Toast.LENGTH_LONG).show(); } } private String sendAndReceive() { HttpURLConnection con = Connector.connect(urlAddress); if(con==null) { return null; } try { OutputStream os = con.getOutputStream(); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os)); bw.write(new DataPackager(query).packageData()); bw.flush(); bw.close(); os.close(); int responseCode = con.getResponseCode(); if(responseCode==con.HTTP_OK) { InputStream is = con.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); if(br != null) { while ((line=br.readLine()) != null) { response.append(line+"n"); } } else { return null; } return response.toString(); } else { return String.valueOf(responseCode); } } catch (IOException e) { e.printStackTrace(); } return null; } } DataPackager.java public class DataPackager { String query; public DataPackager(String query) { this.query = query; } public String packageData() { JSONObject jo = new JSONObject(); StringBuffer queryString = new StringBuffer(); try { jo.put("Query",query); Boolean firstValue = true; Iterator it = jo.keys(); do { String key = it.next().toString(); String value = jo.get(key).toString(); if(firstValue) { firstValue = false; } else { queryString.append("&"); } queryString.append(URLEncoder.encode(key,"UTF-8")); queryString.append("="); queryString.append(URLEncoder.encode(value,"UTF-8")); } while (it.hasNext()); return queryString.toString(); } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } }