Witam,
jestem początkującym pasjonatem kodowania aplikacji na Androida. To jest mój pierwszy post na tym forum. Jeżeli popełniam jakąś gafę to proszę o wyrozumiałość.
Proszę szacowne grono ekspertów o pomoc w rozwiązaniu problemu dotyczącego wrzucenia elementów (to są dane klienta: id, name, surname, phone) z bazy danych MySQL do ListView. To stanowi jeden wiersz w ListView. Po naciśnięciu wiersza w ListView otwiera się nowa intencja z podglądem klienta.
Mam już tak w metodzie onPostExecute:
for (int i=0; i < customers.length(); i ++) {
JSONObject customer = customers.getJSONObject(i);
int customer_id = customer.getInt("customer_id");
String customer_name = customer.getString("customer_name");
String customer_surname = customer.getString("customer_surname");
int customer_phone_number = customer.getInt("customer_phone_number");
String customer_verify = customer.getString("customer_phone_number");
String customer_registrationdate = customer.getString("customer_registrationdate");
// String line = customer_id + "\n" + customer_name + " "+ customer_surname + "\n" + customer_phone_number + "\n" + "DATA REJESTRACJI: " + customer_registrationdate;
//adapter.add(line);
}
W powyższym przykładzie wszystko wrzucałem do String line, ciężko z tego później wyciągnąć id, które posłuży do przekazania do nowej intencji i na podstawie tego id uzyskać cały profil klienta.
Oczywiście takie rozwiązanie ja zaproponowałem.
EDIT:
Wpadłem na taki pomysł:
adapter.add(customer_id + "\n" + customer_name + " " + customer_surname + "\n" + customer_phone_number);
tylko jak teraz przekazać customer_id do kolejnej intencji po naciśnięciu el. w listview?
EDIT:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//Toast.makeText(CustomerListActivity.this, adapter.getItem(i).toString(), Toast.LENGTH_SHORT).show();
//setResult(RESULT_OK, new Intent().putExtra(String.valueOf(ViewCustomer.class),i));
//Intent intent = new Intent(in, ViewCustomer.class);
// intent.putExtra("name", myText);
// Intent intent = (Intent) new Intent(null, ViewCustomer.class);
Intent intent = (Intent) new Intent(getApplicationContext(), ViewCustomer.class);
intent.putExtra(null, i);
startActivity(intent);
finish();
}
});
Jednak brakuje mi przekazania customer_id do nowej intencji