title: On Item Click for List View
body: <p>I have an List view and a button in a Linear layout. I cannot extend ListActivity(to use Onlistitemclick) , but I have to select an Item in the list view which opens up another view , where I have to fill in the details from SQLite DB. </p>
  
  <p>What is the best method to implement this for the following code assuming the database works ? I am a beginner. All suggestion related to the method and the code are welcome.</p>
  
  <p>Thanks in advance,</p>
  
  <pre><code>public class Contacts extends Activity implements OnClickListener {
      int NewContact_Request_Code = 1;
      Button newcontact;
      ListView listview;
      public static final String LOG_TAG = "Contacts";
      int mInt = 0;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.contactview);
          // Set the content to contactview.xml
  
          // newcontact = NEW CONTACT button
          // listview = MyList List View
          newcontact = (Button) findViewById(R.id.baddcontact);
          listview = (ListView) findViewById(R.id.mylist);
  
          // Make a New Database
          DBContact info = new DBContact(this);
          // Open , get Information from database and close it
          info.open();
          String[] data = info.queryAll();
          info.close();
          // listview = getListView();
          listview.setTextFilterEnabled(true);
          // Display the names
       ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(Contacts.this, android.R.layout.simple_list_item_1, data);
           listview.setAdapter(adapter);
          newcontact.setOnClickListener(this);
  
      }
  
      // @Override
      // protected void onListItemClick(ListView l, View v, int position, long id)
      // {
      // // TODO Auto-generated method stub
      // super.onListItemClick(l, v, position, id);
      // Intent viewintent = new Intent(Contacts.this, ViewContact.class);
      // String item = (String) getListAdapter().getItem(position);
      // viewintent.putExtra("name_clicked", item);
      // startActivity(viewintent);
      //
      // }
  
  
  
      public void onClick(View v) {
          // TODO Auto-generated method stub
          Intent newintent = new Intent(Contacts.this, AddNewContact.class);
          // start actiivity for result - to get the name of the new contact
          startActivityForResult(newintent, 0);
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          // TODO Auto-generated method stub
          super.onActivityResult(requestCode, resultCode, data);
          // pass the value of the string via cursor and update the list
      }
  
  }
  </code></pre>