Buon giorno a tutti,
Sto ottenendo i dati via socket con questo metodo e al suo interno volevo collegare l'adapter ma non ci riesco perche con so come collegare il modello Busta all'array che contiene i dati(arrayBusta):
Questo il Modello :codice:@Overrideprotected Object doInBackground(Object[] objects) { ArrayList<String> arrayBusta = null; try { Socket socket = new Socket("192.168.1.67",porta); arrayBusta = new ArrayList<String>(); try { ObjectInputStream objectInput = new ObjectInputStream(socket.getInputStream()); //Error Line! try { Object object = objectInput.readObject(); arrayBusta = (ArrayList<String>) object; for (int i = 0; i < arrayBusta.size(); i++) { // String get = arrayBusta.get(i); System.out.println(arrayBusta.get(i)); } List list = new LinkedList(); list.add(arrayBusta.get(0)); list.add(arrayBusta.get(1)); //provo a connettere l'adapter ma non ci riesco AdaperRisultato adaperRisultato = new AdaperRisultato(this,R.layout.adapter_row,list); } catch (ClassNotFoundException e) { System.out.println("The title list has not come from the server"); e.printStackTrace(); } } catch (IOException e) { System.out.println("The socket for reading the object has problem"); e.printStackTrace(); } } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return arrayBusta; }}
Questo l'adapter:codice:public class Busta { String Nbusta, Nome; public Busta(String codice, String nome) { this.Nbusta = codice; this.Nome = nome; } public String getNbusta() { return Nbusta; } public void setNbusta(String nbusta) { this.Nbusta = nbusta; } public String getNome() { return Nome; } public void setNome(String nome) { this.Nome = nome; } }
Il mio problema sostanzialmente è come collegare il modello Busta ai dati provenienti dal socket "in parole povere"codice:public class AdaperRisultato extends ArrayAdapter<Busta> { public AdaperRisultato(Context context, int resource) { super(context, resource); } @NonNull @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.adapter_row,null); TextView Nbusta = (TextView)convertView.findViewById(R.id.tVNbusta); TextView Nome = (TextView)convertView.findViewById(R.id.tVNome); Busta b = getItem(position); Nbusta.setText(b.getNbusta()); Nome.setText(b.getNome()); return convertView; } }

Rispondi quotando