title: How to display multiple columns from a prepopoulated database in list view?
body: <p>This is my main activity in which I am using a pre-populated database. I am trying to display the rows in list view. There are five columns in my database out of which I want to display all columns except id.</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener{
  
  private IngHelper dbIngHelper = null;
  private Cursor curname=null;
  private SimpleCursorAdapter adapter = null;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ListView myList; 
      myList = (ListView)findViewById(R.id.listView1);
  
      dbIngHelper = new IngHelper(this);
      dbIngHelper.createDB();
      dbIngHelper.openDB();
  
  
      fillData();
  }
  
  
  public void fillData(){
  
      //ListView myList; 
      ListView myList; 
      myList = (ListView)findViewById(R.id.listView1);
      curname=dbIngHelper.getCursor();
      startManagingCursor(curname);
      String[] columns = new String[] {
              IngHelper.COLUMN_ID,
              IngHelper.COLUMN_NAME,
              IngHelper.COLUMN_NATURE,
              IngHelper.COLUMN_SECTION,
              IngHelper.COLUMN_PENALTY
        };
  
      int[] to = new int[] { 
              R.id.id,
              R.id.name,
              R.id.nature,
              R.id.penalty,
              R.id.section
            };
  
      adapter = new SimpleCursorAdapter(
              this, R.layout.activity_main, 
              curname, 
              columns, 
              to);
  
  
  
      myList.setAdapter(adapter);
  
  
  
  myList.setOnItemClickListener(new OnItemClickListener() {
     public void onItemClick(AdapterView&lt;?&gt; listView, View view,int position, long   id) {
     //Get the cursor, positioned to the corresponding row in the result set
     // Cursor cursor = (Cursor) listView.getItemAtPosition(position);
  
  
     }
  });
  }
  
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
  }
  
  class IngAdapter extends CursorAdapter{
      @SuppressWarnings("deprecation")
      IngAdapter(Cursor c){
          super(MainActivity.this,c);
      }
  
      @Override
      public void bindView(View row, Context ctxt, Cursor c) {
          // TODO Auto-generated method stub
  
          IngHolder holder=(IngHolder)row.getTag();
          holder.populateFrom(c,dbIngHelper);
  
  
      }
  
      @Override
      public View newView(Context cxtx, Cursor c, ViewGroup parent) {
          // TODO Auto-generated method stub
          LayoutInflater inf = getLayoutInflater();
          View row=inf.inflate(R.layout.row, parent, false);
          IngHolder holder = new IngHolder(row);
          row.setTag(holder);
          return(row);
      }
  
  }
  
  static class IngHolder{
      private TextView name=null;
     //   private TextView nature=null;
      //private TextView section=null;
      //private TextView penalty=null;
  
      IngHolder(View row){
  
          name=(TextView)row.findViewById(R.id.name);
  
      }
  
      void populateFrom(Cursor c,IngHelper r){
  
          name.setText(r.getName(c));
  
  
      }
  
  
  }
  
  @Override
  public void onClick(View arg0) {
      // TODO Auto-generated method stub
  
  }
  }
  </code></pre>
  
  <p>This is database class IngHelper.java</p>
  
  <pre><code>  public class IngHelper extends SQLiteOpenHelper{
  
  
  private static final String DATABASE_PATH =        "//data//data//com.example.db//databases//";
  private static final String DATABASE_NAME = "traffic.sqlite";
  private static final int SCHEMA_VERSION = 1;
  public static final String TABLE_NAME="mumbai";
  public static final String COLUMN_ID="_id";
  public static final String COLUMN_NAME="name";
  public static final String COLUMN_NATURE="nature";
  public static final String COLUMN_SECTION="section";
  public static final String COLUMN_PENALTY="penalty";
  
  
  public SQLiteDatabase dbSqlite;
  
  private final Context myCnt;
  
  public IngHelper (Context context)
  {
      super(context, DATABASE_NAME, null, SCHEMA_VERSION);
      this.myCnt=context;
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      // TODO Auto-generated method stub
  
  }
  
  public void createDB(){
  
      boolean dbExist = DBExist();
  
      if(!dbExist){
  
          this.getReadableDatabase();
  
          copyDBFromResource();
      }
  }
  
  private boolean DBExist(){
      SQLiteDatabase db = null;
  
      try{
          String dbPath = DATABASE_PATH + DATABASE_NAME;
          db = SQLiteDatabase.openDatabase(dbPath, null,     SQLiteDatabase.OPEN_READWRITE);
          db.setLocale(Locale.getDefault());
          db.setLockingEnabled(true);
          db.setVersion(1);
      }catch(SQLiteException e){
          Log.e("SqlHelper", "db nt found");
          }
  
      return db != null ? true : false;
  }
  
  private void copyDBFromResource(){
      InputStream iS =null;
      OutputStream oS = null;
      String dbFilePath = DATABASE_PATH + DATABASE_NAME;
  
      try{
           iS = myCnt.getAssets().open(DATABASE_NAME);
  
           oS = new FileOutputStream(dbFilePath);
  
           byte[] buffer = new byte[1024];
           int length;
           while((length=iS.read(buffer))&gt;0){
               oS.write(buffer, 0, length);
           }
  
           oS.flush();
           oS.close();
           iS.close();
      }catch(IOException e){
          throw new Error("Prob copyin db from resource file.");
      }
  
  }
  
  public void openDB()throws SQLException {
      String myPath = DATABASE_PATH + DATABASE_NAME;
      dbSqlite = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
  }
  
  @Override
  public synchronized void close() {
      // TODO Auto-generated method stub
      if(dbSqlite != null)
      {
          dbSqlite.close();
      }
      super.close();
  }
  
  
  public Cursor getCursor(){
      SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
      qBuilder.setTables(TABLE_NAME);
      String[] asColmToRetrn = new String[] {COLUMN_ID, COLUMN_NAME, COLUMN_NATURE, COLUMN_SECTION, COLUMN_PENALTY};
  
      Cursor mCur = qBuilder.query(dbSqlite, asColmToRetrn, null, null, null, null, null);
  
      if (mCur != null) {
         mCur.moveToFirst();
        }
        return mCur;
  
       }
  
  
  
  public String getName(Cursor c){
      return(c.getString(1));
  
  
  }
  
  }
  </code></pre>
  
  <p>There are two xml files. This is activity_main.xml... It has a list View.</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent" &gt;
  
  
  
  &lt;ListView
      android:id="@+id/listView1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true" &gt;
  
  &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Another layout is row.xml file. Here I am creating a text View for each column in my database. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
  &lt;TextView
      android:id="@+id/id"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      android:text="TextView" /&gt;
  
  &lt;TextView
      android:id="@+id/name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      android:text="TextView" /&gt;
  
  &lt;TextView
      android:id="@+id/nature"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      android:text="TextView" /&gt;
  
  &lt;TextView
      android:id="@+id/section"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textColor="#000000"
      android:text="TextView" /&gt;
  
  &lt;TextView
      android:id="@+id/penalty"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textColor="#000000"
  
      android:text="TextView" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I am getting a blank list as output with a list entry for each row but the data cannot be seen. please give some suggestions to resolve the problem</p>