Click here to Skip to main content
15,888,984 members
Home / Discussions / Android
   

Android

 
GeneralRe: Table rows not scrolling Pin
pkfox25-Jul-15 23:11
professionalpkfox25-Jul-15 23:11 
AnswerRe: Table rows not scrolling Pin
Member 1190643213-Aug-15 0:43
Member 1190643213-Aug-15 0:43 
GeneralRe: Table rows not scrolling Pin
pkfox14-Aug-15 3:09
professionalpkfox14-Aug-15 3:09 
QuestionHow to start in Android programming Pin
aahamdan24-Jul-15 8:42
aahamdan24-Jul-15 8:42 
AnswerRe: How to start in Android programming Pin
Richard MacCutchan24-Jul-15 22:31
mveRichard MacCutchan24-Jul-15 22:31 
GeneralRe: How to start in Android programming Pin
aahamdan26-Jul-15 9:00
aahamdan26-Jul-15 9:00 
AnswerRe: How to start in Android programming Pin
IlaSNema10-Aug-15 20:43
IlaSNema10-Aug-15 20:43 
QuestionSQLite Database help Pin
Member 1185517022-Jul-15 3:58
Member 1185517022-Jul-15 3:58 
When I run my app in Android Studio I get the message "Unfortunately your App Appointment DB has stopped working". Not sure how to resolve this issue. Here is my code.

MainActivity.java

package com.example.android.appointmentdb;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {

    TextView idView;
    EditText clientNameBox;
    EditText clientPhoneBox;
    EditText clientTimeBox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        idView = (TextView) findViewById(R.id.clientID);
        clientNameBox = (EditText) findViewById(R.id.clientName);
        clientPhoneBox =(EditText) findViewById(R.id.clientPhone);
        clientTimeBox =(EditText) findViewById(R.id.clientTime);
    }

    public void newClient (View view) {
        MyDBHandler dbHandler = new MyDBHandler(this, null, null, 1);


        String phone = clientPhoneBox.getText().toString();

        String name = clientNameBox.getText().toString();

        String time = clientTimeBox.getText().toString();

        Appointment newAppointment = new Appointment(name, phone, time);

        dbHandler.addClient(newAppointment);


        Toast.makeText(getApplicationContext(), "Your appointment is set =)",
                Toast.LENGTH_LONG).show();

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}


MyDBHandler.java

package com.example.android.appointmentdb;

/**
 * Created by Jamila on 7/16/2015.
 */
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;

public class MyDBHandler extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "thursdayDB.db";
    private static final String TABLE_APPOINTMENTS = "7-16-2015";

    public static final String COLUMN_ID = "_id";
    public static final String COLUMN_CLIENTNAME = "clientname";
    public static final String COLUMN_CLIENTPHONE = "clientphone";
    public static final String COLUMN_CLIENTTIME = "clienttime";

    public MyDBHandler(Context context, String name,
                       SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DATABASE_NAME, factory, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        String CREATE_PRODUCTS_TABLE = "CREATE TABLE " +
                TABLE_APPOINTMENTS + "("
                + COLUMN_ID + " INTEGER PRIMARY KEY,"
                + COLUMN_CLIENTNAME+ " TEXT,"
                + COLUMN_CLIENTPHONE + " TEXT,"
                + COLUMN_CLIENTTIME + " TEXT" + ")";
        db.execSQL(CREATE_PRODUCTS_TABLE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion,
                          int newVersion) {

        db.execSQL("DROP TABLE IF EXISTS " + TABLE_APPOINTMENTS);
        onCreate(db);

    }

    public void addClient(Appointment appointment) {

        ContentValues values = new ContentValues();
        values.put(COLUMN_CLIENTNAME, appointment.getClientName());
        values.put(COLUMN_CLIENTPHONE, appointment.getClientPhone());
        values.put(COLUMN_CLIENTTIME, appointment.getClientTime());

        SQLiteDatabase db = this.getWritableDatabase();

        db.insert(TABLE_APPOINTMENTS, null, values);
        db.close();
    }

    public Appointment findAppointment(String clientname) {
        String query = "Select * FROM " + TABLE_APPOINTMENTS + " WHERE " + COLUMN_CLIENTNAME + " =  \"" + clientname + "\"";

        SQLiteDatabase db = this.getWritableDatabase();

        Cursor cursor = db.rawQuery(query, null);

         Appointment appointment = new Appointment();

        if (cursor.moveToFirst()) {
            cursor.moveToFirst();
            appointment.setID(Integer.parseInt(cursor.getString(0)));
            appointment.setClientName(cursor.getString(1));
            appointment.setClientPhone(cursor.getString(2));
            appointment.setClientTime(cursor.getString(3));
            cursor.close();
        } else {
            appointment = null;
        }
        db.close();
        return appointment;
    }

}


Appointment.java

C#
package com.example.android.appointmentdb;

/**
 * Created by Jamila on 7/16/2015.
 */
public class Appointment {

    private int _id;
    private String _clientName;
    private String _clientPhone;
    private String _clientTime;

    public Appointment() {

    }

    public Appointment(int id, String clientName, String clientPhone, String clientTime) {
        this._id = id;
        this._clientName = clientName;
        this._clientPhone = clientPhone;
        this._clientTime = clientTime;
    }

    public Appointment(String clientName, String clientPhone, String clientTime) {
        this._clientName = clientName;
        this._clientPhone = clientPhone;
        this._clientTime = clientTime;
    }

    public void setID(int id) {
        this._id = id;
    }

    public int getID() {
        return this._id;
    }

    public void setClientName(String clientName) {
        this._clientName = clientName;
    }

    public String getClientName() {
        return this._clientName;
    }

    public void setClientTime(String clientTime) {
        this._clientTime = clientTime;
    }

    public String getClientTime() {
        return this._clientTime;
    }

    public void setClientPhone(String clientPhone) {
        this._clientPhone = clientPhone;
    }

    public String getClientPhone() {
        return this._clientPhone;
    }
}


activity_main.xml

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/id_string"
                android:id="@+id/textView" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text=""
                android:id="@+id/clientID" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/name_string"
                android:id="@+id/textView3" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/clientName" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/phone_string"
                android:id="@+id/textView2" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="phone"
                android:ems="10"
                android:id="@+id/clientPhone" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/time_string"
                android:id="@+id/textView1" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="time"
                android:ems="10"
                android:id="@+id/clientTime" />
        </TableRow>
    </TableLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center_horizontal"
        android:layout_margin="10dp">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/book_string"
            android:id="@+id/button"
            android:onClick="newClient"/>

           </LinearLayout>
</LinearLayout>

AnswerRe: SQLite Database help Pin
Richard MacCutchan22-Jul-15 6:22
mveRichard MacCutchan22-Jul-15 6:22 
GeneralRe: SQLite Database help Pin
Member 1185517022-Jul-15 6:31
Member 1185517022-Jul-15 6:31 
GeneralRe: SQLite Database help Pin
Richard MacCutchan22-Jul-15 7:37
mveRichard MacCutchan22-Jul-15 7:37 
GeneralRe: SQLite Database help Pin
Member 1185517022-Jul-15 8:47
Member 1185517022-Jul-15 8:47 
GeneralRe: SQLite Database help Pin
Richard MacCutchan22-Jul-15 21:08
mveRichard MacCutchan22-Jul-15 21:08 
SuggestionRe: SQLite Database help Pin
David Crow27-Jul-15 5:06
David Crow27-Jul-15 5:06 
Questionandroid listview display data in sdcard to top position in my listciew. Pin
ashish77309-Jul-15 19:17
ashish77309-Jul-15 19:17 
AnswerRe: android listview display data in sdcard to top position in my listciew. Pin
Richard MacCutchan9-Jul-15 22:08
mveRichard MacCutchan9-Jul-15 22:08 
QuestionPanorama viewer with gyro support - Html5 Pin
martin prochazka 19799-Jul-15 11:50
martin prochazka 19799-Jul-15 11:50 
AnswerRe: Panorama viewer with gyro support - Html5 Pin
Richard MacCutchan9-Jul-15 22:05
mveRichard MacCutchan9-Jul-15 22:05 
GeneralRe: Panorama viewer with gyro support - Html5 Pin
martin prochazka 197912-Jul-15 3:42
martin prochazka 197912-Jul-15 3:42 
QuestionUploading Video to server through SOAP webservice using Android Pin
Member 116050787-Jul-15 0:02
Member 116050787-Jul-15 0:02 
AnswerRe: Uploading Video to server through SOAP webservice using Android Pin
Richard MacCutchan7-Jul-15 1:58
mveRichard MacCutchan7-Jul-15 1:58 
QuestionHow to implement unlimited number of text views Pin
jasonalien6-Jul-15 21:46
jasonalien6-Jul-15 21:46 
AnswerRe: How to implement unlimited number of text views Pin
Richard MacCutchan6-Jul-15 22:05
mveRichard MacCutchan6-Jul-15 22:05 
QuestionWebsocket timeout via NGINX only in a 3G hotspot Pin
Dickens A S2-Jul-15 16:53
professionalDickens A S2-Jul-15 16:53 
QuestionGalery camera android Pin
Ibrahim.elh2-Jul-15 2:42
Ibrahim.elh2-Jul-15 2:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.