Beispiel #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_contact);
    name = (TextView) findViewById(R.id.editTextName);
    phone = (TextView) findViewById(R.id.editTextPhone);
    email = (TextView) findViewById(R.id.editTextStreet);
    street = (TextView) findViewById(R.id.editTextEmail);
    place = (TextView) findViewById(R.id.editTextCity);

    mydb = new DBHelper(this);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      int Value = extras.getInt("id");

      if (Value > 0) {
        // means this is the view part not the add contact part.
        Cursor rs = mydb.getData(Value);
        id_To_Update = Value;
        rs.moveToFirst();

        String nam = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_NAME));
        String phon = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_PHONE));
        String emai = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_EMAIL));
        String stree = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_STREET));
        String plac = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_CITY));

        if (!rs.isClosed()) {
          rs.close();
        }
        Button b = (Button) findViewById(R.id.button1);
        b.setVisibility(View.INVISIBLE);

        name.setText((CharSequence) nam);
        name.setFocusable(false);
        name.setClickable(false);

        phone.setText((CharSequence) phon);
        phone.setFocusable(false);
        phone.setClickable(false);

        email.setText((CharSequence) emai);
        email.setFocusable(false);
        email.setClickable(false);

        street.setText((CharSequence) stree);
        street.setFocusable(false);
        street.setClickable(false);

        place.setText((CharSequence) plac);
        place.setFocusable(false);
        place.setClickable(false);
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final TextView nameTextview = (TextView) findViewById(R.id.name_display);
    final TextView emailTextview = (TextView) findViewById(R.id.email_display);

    Cursor cursor = dbHelper.getData();
    if (cursor != null) {
      if (cursor.moveToFirst())
        do {
          String name = cursor.getString(cursor.getColumnIndex(DBHelper.CONTACTS_COLUMN_NAME));
          String email = cursor.getString(cursor.getColumnIndex(DBHelper.CONTACTS_COLUMN_EMAIL));

          result.add(name + "   " + email);
        } while (cursor.moveToNext());
    }
    displayResultList();
  }