0

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.

masgar
  • 1,875
  • 2
  • 20
  • 32
  • Would you have 10 rows if your query returned 2 records? – Dan Harms May 16 '16 at 16:49
  • I suspect that you want each row to show all data for a person. In other words, each row from the SQL query would correspond to a ListView row. – Cheticamp May 16 '16 at 16:52
  • it cannot returns more than 1 record. When I tap a row in friends list I do a conditional select with unique ID for that friend. – masgar May 16 '16 at 16:53
  • http://stackoverflow.com/a/4777306/5612089 and http://android.amberfog.com/?p=296 this two links explains what you are looking for – Vishwesh Jainkuniya May 16 '16 at 16:56
  • Thanks for reply but that tutorial is not what I need. In iOS I can set the number of rows the table must have and then fill each rows with what I like. Here the position is always 0 because the sql query returns only 1 result so the cursor.getcount is always 1 and whilst only 1 row. What I need is to set 5 rows even if the cursor contains only 1 object. The Leonid answer seems to make sense but I don't know how to clone the cursor. Thanks – masgar May 17 '16 at 15:19

0 Answers0