Hi,

 

I'm newbie on android develop....i have a question about  how i implement my
db  columns into a listview...

I do this code below but I display wich column in one row..how I display one
or more columns in one row.has anyone had an reference to send me.

 

public class Restaurants extends ListActivity {      

      private ArrayList<RestaurantsInfo> mListRestaurants;

      

      @Override

      public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            try {

                  setContentView(R.layout.restaurants);

                    mListRestaurants = getRestaurants();

                    List<String> items = new ArrayList<String>();

                    for(RestaurantsInfo restaurant:mListRestaurants){

                        items.add(restaurant.res_name);

                        items.add(restaurant.res_city);


                    }

                    //display into a restaurant_row.xml

                    ArrayAdapter<String> adapter =   new
ArrayAdapter<String>(this, R.layout.restaurant_row,items);

                  setListAdapter(adapter); 

                  

            } catch (Exception e) {

                  // TODO: handle exception

                  Log.e("oncreate resta",e.getMessage());

            }

             

        

      }

      public ArrayList<RestaurantsInfo> getRestaurants(){

            String query = "Select * from restaurants";

            ArrayList<RestaurantsInfo> lstRestaurants = new
ArrayList<RestaurantsInfo>();

            DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);

            try {

                  dbAdapter.createDataBase();

            } catch (IOException e) {

                  // TODO: handle exception

                  Log.e("*** select ",e.getMessage());

            }

            dbAdapter.openDataBase();

            ArrayList<ArrayList<String>> stringList =
dbAdapter.selectRecordsFromDBList(query, null);

            dbAdapter.close();

            for (int i = 0; i < stringList.size(); i++) {

                  ArrayList<String> list = stringList.get(i);

                  RestaurantsInfo restaurant = new RestaurantsInfo();

                  try {

                        restaurant.res_id = Integer.parseInt(list.get(0));

                        restaurant.res_name = list.get(1);

                        restaurant.res_address = list.get(2);

                        restaurant.res_number = list.get(3);

                        restaurant.res_neiborhood = list.get(4);

                        restaurant.res_image = list.get(5);

                        restaurant.res_lat = list.get(6);

                        restaurant.res_long = list.get(7);

                        restaurant.res_city = list.get(8);

                        

                  } catch (Exception e) {

                        Log.i("***" + Restaurants.class.toString(),
e.getMessage());

                  }

                  lstRestaurants.add(restaurant);

            }

            return lstRestaurants;

      }

      

}

// restaurant_row.xml

<?xml version="1.0" encoding="utf-8"?>

<TextView android:id="@+id/text1" xmlns:android="http://

schemas.android.com/apk/res/android"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"/>

 

Thanks very much !

Igor Nesralla Ribeiro

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to