I am bringing data from rows of a DB and I want to display them on listview. Imagine that I am bringing names and phones, so I want each row of listview to have the telephone and the name.
So far this is my code: (the items are being brought up normally, I see them using system.out. ptintln). So in info[0] i have the name, and in info [1] I have the phone.
this is my adapter code.
public class FacilitiesAdapter extends ArrayAdapter<String> {
private final Context context;
private String data[] = null;
public FacilitiesAdapter(Context context, String[] data) {
super(context, R.layout.expand_row);
this.context = context;
this.data = data;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.expand_row, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.name);
System.out.println("I am in the adapter "+data[0]);
textView.setText(data[0]);
TextView textView2 = (TextView) rowView.findViewById(R.id.phone);
textView2.setText(data[1]);
return rowView;
}
}
So i suppose that with the above code, i must see in each line the data 0 and the data[1] (phone)? But I am wrong. Why is that?
This is my javacode:
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
//each line fetches a line of the table
JSONObject json_data = jArray.getJSONObject(i);
if (json_data.getString("Name")!=null) info[0]=json_data.getString("Name");
if (json_data.getString("Phone")!=null) info[1]=json_data.getString("Phone");
FacilitiesAdapter adapter = new FacilitiesAdapter(this,info);
System.out.println(info[0]);
setListAdapter(adapter);