I'm trying to port my iOS app to Android.
I have a ListView with a list of friend (Name and Lastname). All rows have same layout. When I tap on a row I switch activity to friend details.
with iOS i use a tableview (ListView) where I set the number of rows and if row == 0 do this, else if row == 1 do that etc etc.
I get friend details from a sqlite db that returns only 1 record with i.e: name, lastname, age, sex, address, hobbies, etc etc.
My details listview should have only 5 rows where if row == 0 inflate layout "name" that has 2 textview for name and lastname, if row == 1 inflate layout "address" that has 3 textview for address, city and country, etc etc
In my adapter I implemented:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
LayoutInflater inflater = (LayoutInflater) mcontext.getSystemService(mcontext.LAYOUT_INFLATER_SERVICE);
if (position == 0) {
view = inflater.inflate(R.layout.ddetrow1, parent, false);
tvdetname.setText("#" + detName);
tvdetlastname.setText(detLastname);
tvdetname.setFocusable(false);
tvdetlastname.setFocusable(false);
}
else if (position == 1) {
view = inflater.inflate(R.layout.ddetrow2, parent, false);
tvdetaddr.setText(detAddr);
tvdetcity.setText(detCity);
tvdetcountry.setText(detCountry);
tvdetaddr.setFocusable(false);
tvdetcity.setFocusable(false);
tvdetcountry.setFocusable(false);
}
..........
return view;
}
It works but it shows only row 0, I suppose because the sql query returns only 1 record.
How can I set 5 rows to show all other details?
I tried to implement:
public int getCount() {
return 5;
}
But app crash because there is only 1 record. Probably is my approach to be wrong because I try to do the same I did with iOS.
I need a ListView because when user tap on a specific row I need to switch activity to edit the values showed in that row.
Thanks.