I'm trying to write form which make reservation and save it mysql. So there are 4-5 field in the form name, phone, email, comment, time, date, table, people
. I must tell that I'm very new in Java and Android and don't know how to do this but I'm trying. Also I think that code is really mess right now so I need some help. Here is the code so far of Reservation.java
public class Reservation extends Activity implements
OnClickListener {
String Name;
String Email;
String Phone;
String Comment;
String DateTime;
String Time;
String Table;
String numberOfPeople;
private EditText editText1, editText3, editText2, editText4, txtDate, txtTime;
private Button btnCalendar, btnTimePicker, btnMenues;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reservation);
editText1 = (EditText) findViewById(R.id.editText1);
editText3 = (EditText) findViewById(R.id.editText3);
editText2 = (EditText) findViewById(R.id.editText2);
editText4 = (EditText) findViewById(R.id.editText4);
txtDate = (EditText) findViewById(R.id.txtDate);
txtTime = (EditText) findViewById(R.id.txtTime);
btnCalendar = (Button) findViewById(R.id.btnCalendar);
btnTimePicker = (Button) findViewById(R.id.btnTimePicker);
btnMenues = (Button) findViewById(R.id.btnMenues);
btnMenues.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Name = editText1.getText().toString();
Phone = editText3.getText().toString();
Email = editText2.getText().toString();
Comment = editText4.getText().toString();
DateTime = txtDate.getText().toString();
DateTime = txtTime.getText().toString();
new SummaryAsyncTask().execute((Void) null);
}
});
}
class SummaryAsyncTask extends AsyncTask<Void, Void, Boolean> {
private void postData(String name, String email, String phone,
String comment, String date, String table, String numberofpeople) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://link.to.server.com/saveReservation.php");
try {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("Name", name));
nameValuePairs.add(new BasicNameValuePair("Email", email));
nameValuePairs.add(new BasicNameValuePair("Phone", phone));
nameValuePairs.add(new BasicNameValuePair("Comment", comment));
nameValuePairs.add(new BasicNameValuePair("Date", date));
nameValuePairs.add(new BasicNameValuePair("Table", table));
nameValuePairs.add(new BasicNameValuePair("numberOfPeople", numberofpeople));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
@Override
protected Boolean doInBackground(Void... params) {
postData(Name, Email, Phone, Comment, DateTime, Time, Table );
return null;
}
}
}
Currently the error that I get is
The type Reservation must implement the inherited abstract method View.OnClickListener.onClick(View) Update:
And how to save date and time in database in one row or two? If is one row how to make it this in android side?
UDPATE2: How to implement now btnCalendar, btnTimePicker
I have them in the reservation.xml
and they are in form. I must implement date and time picker in this code?
You implements OnClickListener
but you do not over ride onClick(View view)
method of onclicklistener interface which is mandatory. So please override method first and remove on click listener
from oncreate
method.
See below link for more information:-
Your class implements onClick listener however you lack the method.
Either remove implement
statement or override the method
The problem of your logcat is here:
public class Reservation extends Activity implements OnClickListener
You are implementing OnClickListener
and then you are implementing an anonymous onClickListener
in your btnMenues
. Remove your implements OnClickListener
and the error will go away.
I think the problem is
public class Reservation extends Activity implements OnClickListener
just remove
implements OnClickListener
You don't need this