title: Android Custom XML layout for SQLite
body: <p>So I have been working on a project app that reads from a database and prints the contents of the DB into a list view. I now want to print more then just one column, I want to add two buttons and an edittext to the row that is being printed. I have created the new xml file that I want to use but when i try to set the new layout to be this xml file it doesnt work. Can anyone explain or show me how to fix my problem?</p>
  
  <p>This is the XML layout I want to use for each row
      </p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"&gt;
  
  &lt;TextView android:id="@+id/item1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="30sp"
      android:paddingBottom="5dp"
      android:hint="@string/hint"/&gt;
  
  &lt;Button
      android:id="@+id/plusButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/plusButton"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;EditText
      android:id="@+id/edit1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:hint="@string/hint"
      android:layout_alignParentTop="true"
      android:layout_toLeftOf="@+id/minusButton"
      android:layout_toStartOf="@+id/minusButton"
      android:layout_marginRight="30dp" /&gt;
  
  &lt;Button
      android:id="@+id/minusButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/minusButton"
      android:layout_alignParentTop="true"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And this is the class where I am displaying the contents of the SQLite database, the error occurs on line 100 when i try to change the android.R.layout to the row.xml file</p>
  
  <pre><code>package com.example.rory.dbtest;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.app.ListActivity;
  import android.content.Intent; 
  import android.database.Cursor;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.BaseAdapter;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.Toast;
  
  import com.pinchtapzoom.R;
  
  public class MyActivity extends Activity {
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      setContentView(R.layout.activity_my);
  
      Button addBtn = (Button)findViewById(R.id.add);
      addBtn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent i = new Intent(MyActivity.this, addassignment.class);
              startActivity(i);
          }
      });
  
      Button deleteBtn = (Button)findViewById(R.id.delete);
      deleteBtn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent i = new Intent(MyActivity.this, Delete.class);
              startActivity(i);
          }
      });
  
      Button updateBtn = (Button)findViewById(R.id.update);
      updateBtn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent i = new Intent(MyActivity.this, Update.class);
              startActivity(i);
          }
      });
  
  
      try {
          String destPath = "/data/data/" + getPackageName() + "/databases/AssignmentDB";
          File f = new File(destPath);
          if (!f.exists()) {
              CopyDB( getBaseContext().getAssets().open("mydb"),
                      new FileOutputStream(destPath));
          }
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      com.example.rory.dbtest.DBAdapter db = new com.example.rory.dbtest.DBAdapter(this);
      db.open();
  
  
  
      ArrayList&lt;String&gt; data_list=new ArrayList&lt;String&gt;();
      ListView lv=(ListView)findViewById(R.id.listView1);
      Cursor c = db.getAllRecords();
  
      if (c.moveToFirst())
      {
          do {
              data_list.add(c.getString(2));
              //data_list.add(c.getString(1));
              //DisplayRecord(c);
          } while (c.moveToNext());
      }
      ArrayAdapter&lt;String&gt; aa=new ArrayAdapter&lt;String&gt;(getApplicationContext(), android.R.layout.row,  data_list);
      lv.setAdapter(aa);
  
  }
  
  private class DBAdapter extends BaseAdapter {
      private LayoutInflater mInflater;
      //private ArrayList&lt;&gt;
  
      @Override
      public int getCount() {
  
          return 0;
      }
  
      @Override
      public Object getItem(int arg0) {
  
          return null;
      }
  
      @Override
      public long getItemId(int arg0) {
  
          return 0;
      }
  
      @Override
      public View getView(int arg0, View arg1, ViewGroup arg2) {
  
          return null;
      }
  
  }
  
  public void CopyDB(InputStream inputStream, OutputStream outputStream)
          throws IOException {
      //---copy 1K bytes at a time---
      byte[] buffer = new byte[1024];
      int length;
      while ((length = inputStream.read(buffer)) &gt; 0) {
          outputStream.write(buffer, 0, length);
      }
      inputStream.close();
      outputStream.close();
  }
  
  
  
  public void DisplayRecord(Cursor c)
  {
     Toast.makeText(this,
              "id: " + c.getString(0) + "\n" +
                      "Item: " + c.getString(1) + "\n" +
                      "Litres:  " + c.getString(2),
              Toast.LENGTH_SHORT).show();
  }
  
  }
  </code></pre>
  
  <p>My new custom adapter class
      package com.example.rory.dbtest;</p>
  
  <pre><code>import android.content.Context;
  import android.database.Cursor;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.CursorAdapter;
  import android.widget.TextView;
  
  import com.pinchtapzoom.R;
  
  /**
   * Created by Rory on 07/11/2014.
   */
  
  public class MyCustomAdapter extends CursorAdapter {
  
  DBAdapter db = new DBAdapter(this);
  
  private LayoutInflater cursorInflater;
  
  public MyCustomAdapter(Context context, Cursor c) {
      super(context, c);
  
      cursorInflater = (LayoutInflater) context.getSystemService(
              Context.LAYOUT_INFLATER_SERVICE);
  }
  
  @Override
  public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
      return cursorInflater.inflate(R.layout.row, parent, false);
  }
  
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
  
      TextView textViewTitle = (TextView) view.findViewById(R.id.row);
      String title = cursor.getString( cursor.getColumnIndex( DATABASE_TABLE.KEY_ITEM ) )
      textViewTitle.setText(title);
  
  }
  }
  </code></pre>