I have two activities. A,B. A loads 1st and then i open B activity from a button within A. When B opens i load values from sqlite to a listview. I want to get the selected values from one item on listview and after i click one row ill get transfered back to activity A and use those values. The thing is that for each row in listview it holds multiple value. Something like (Not actual code)list((String,String,String,String),(String,String,String,String)). So for each row i have 4 values or so. How can i chose the selected row and the values within?
Here is my code: Activity B
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_locations);
// Show the Up button in the action bar.
db = new DBAdapter(this);
db.open();
final Cursor c = db.getSavedLocations();
locationsList = new ArrayList<String>();
list = (ListView) findViewById(R.id.list);
items = new ArrayList<SearchResults>();
Log.d("","c count: "+c.getCount());
if (c.moveToFirst()) {
do {
items.add(new SearchResults(c.getString(c
.getColumnIndex(DBAdapter.MY_ID)), c.getString(c
.getColumnIndex(DBAdapter.MY_COORD_LAT)), c.getString(c
.getColumnIndex(DBAdapter.MY_COORD_LONG)), c
.getString(c.getColumnIndex(DBAdapter.MY_COORD_NOTE)),
c.getString(c.getColumnIndex(DBAdapter.MY_COORD_DATE))) {
});
} while (c.moveToNext());
}
listAdapter = new ListAdapter(LoadLocationsActivity.this, R.id.list,
items);
list.setAdapter(listAdapter);
db.close();
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
}
});
This is the ListAdapter class i have. dont think its necessary to mention but here it is anw.
public class ListAdapter extends ArrayAdapter<SearchResults> {
private ArrayList<SearchResults> entries;
private Activity activity;
public ListAdapter(LoadLocationsActivity a, int list,
ArrayList<SearchResults> items) {
super(a, list, items);
this.entries = items;
this.activity = a;
}
public static class ViewHolder {
public TextView id;
public TextView lati;
public TextView longi;
public TextView notes;
public TextView date;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
if (v == null) {
LayoutInflater vi = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row, null);
holder = new ViewHolder();
holder.lati = (TextView) v.findViewById(R.id.latLoad);
holder.longi = (TextView) v.findViewById(R.id.longLoad);
holder.notes = (TextView) v.findViewById(R.id.loadNote);
holder.date = (TextView) v.findViewById(R.id.loadDate);
holder.id = (TextView) v.findViewById(R.id.idLoad);
v.setTag(holder);
} else
holder = (ViewHolder) v.getTag();
final SearchResults sr = entries.get(position);
if (sr != null) {
holder.lati.setText(sr.getLatitude());
holder.longi.setText(sr.getLongitude());
holder.notes.setText(sr.getNotes());
holder.date.setText(sr.getDate());
holder.id.setText(sr.getLocationId());
// holder.item2.setText(custom.getSecond());
// Log.d("", sr.getLatitude().toString() + " lat");
// Log.d("", sr.getLongitude().toString() + " long");
// Log.d("", sr.getLocationId().toString() + " id");
// Log.d("", sr.getNotes().toString() + " note");
// Log.d("", sr.getDate().toString() + " date");
}
return v;
}
}
Edit: I guided you wrong people sorry about that. I didnt mean on how can i get the values from that row. But how to get the listview row it self. I changed now my description.