title: "select an item from" listview
body: <p>i'm working in my first android app so i need some help..</p>
  
  <p>I have a listview wich contends values from a SQLite database, i need to select an item, get it's ID and open a new activity... how to do that?</p>
  
  <p>I have an activity which shows the list of items but i don't know how to select the item and open another activity with the item ID.</p>
  
  <pre><code>package chintan.khetiya.sqlite.cursor;
  
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  import chintan.khetiya.sqlite.cursor.Main_Screen.Contact_Adapter;
  import chintan.khetiya.sqlite.cursor.Main_Screen.Contact_Adapter.UserHolder;
  
  public class home_screen extends Activity{
  
  //Button add_btn;
  ListView Contact_listview;
  ArrayList&lt;Contact&gt; contact_data = new ArrayList&lt;Contact&gt;();
  Contact_Adapter cAdapter;
  DatabaseHandler db;
  String Toast_msg;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.home);
  try {
      Contact_listview = (ListView) findViewById(R.id.list_pedidos);
      Contact_listview.setItemsCanFocus(false);
      Contact_listview.setClickable(true);
  
      Set_Referash_Data();
  
  } catch (Exception e) {
      // TODO: handle exception
      Log.e("Error", "" + e);
  }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.Clientes:
              finish();
              startActivity(new Intent(this, Main_Screen.class));
              return true;
  
          case R.id.Productos:
              finish();
              startActivity(new Intent(this, Product_Screen.class));
              return true;
  
          case R.id.Nuevo_Pedido:
              finish();
              startActivity(new Intent(this, home_screen.class));
              return true;
  
          case R.id.Nuevo_Pedido_dentro:
              finish();
              startActivity(new Intent(this, nuevo_pedido.class));
              return true;    
  
          case R.id.salir:
              finish();
              return true;
          default:
      return super.onOptionsItemSelected(item);
  }
  }
  public void Set_Referash_Data() {
  contact_data.clear();
  db = new DatabaseHandler(this);
  ArrayList&lt;Contact&gt; contact_array_from_db = db.Get_Contacts();
  
  for (int i = 0; i &lt; contact_array_from_db.size(); i++) {
  
      int tidno = contact_array_from_db.get(i).getID();
      String name = contact_array_from_db.get(i).getName();
      String mobile = contact_array_from_db.get(i).getPhoneNumber();
      String email = contact_array_from_db.get(i).getEmail();
      Contact cnt = new Contact();
      cnt.setID(tidno);
      cnt.setName(name);
      cnt.setEmail(email);
      cnt.setPhoneNumber(mobile);
  
      contact_data.add(cnt);
  }
  db.close();
  cAdapter = new Contact_Adapter(home_screen.this, R.layout.listview_pedidos_row,
      contact_data);
  Contact_listview.setAdapter(cAdapter);
  cAdapter.notifyDataSetChanged();
  }
  
  public void Show_Toast(String msg) {
  Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
  }
  
  @Override
  public void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  Set_Referash_Data();
  
  }
  
  public class Contact_Adapter extends ArrayAdapter&lt;Contact&gt; {
  Activity activity;
  int layoutResourceId;
  Contact user;
  ArrayList&lt;Contact&gt; data = new ArrayList&lt;Contact&gt;();
  
  public Contact_Adapter(Activity act, int layoutResourceId,
      ArrayList&lt;Contact&gt; data) {
      super(act, layoutResourceId, data);
      this.layoutResourceId = layoutResourceId;
      this.activity = act;
      this.data = data;
      notifyDataSetChanged();
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      UserHolder holder = null;
  
      if (row == null) {
      LayoutInflater inflater = LayoutInflater.from(activity);
  
      row = inflater.inflate(layoutResourceId, parent, false);
      holder = new UserHolder();
      holder.name = (TextView) row.findViewById(R.id.user_name_txt);
      holder.email = (TextView) row.findViewById(R.id.user_email_txt);
      holder.number = (TextView) row.findViewById(R.id.user_mob_txt);
      //holder.edit = (Button) row.findViewById(R.id.btn_update);
      //holder.delete = (Button) row.findViewById(R.id.btn_delete);
      row.setTag(holder);
      } else {
      holder = (UserHolder) row.getTag();
      }
      user = data.get(position);
      //holder.edit.setTag(user.getID());
      //holder.delete.setTag(user.getID());
      holder.name.setText(user.getName());
      holder.email.setText(user.getEmail());
      holder.number.setText(user.getPhoneNumber());
      return row;
  
  }
  
  class UserHolder {
      TextView name;
      TextView email;
      TextView number;
      Button edit;
      Button delete;
  }
  
  }
  </code></pre>
  
  <p>}</p>