package example.android_event_trackingsystem; import - TopicsExpress



          

package example.android_event_trackingsystem; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.json.JSONObject; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class Staff_Reg extends Activity{ EditText editText_full_name,editText_email_address,editText_password,editText_confirm_password,editText_deptt; String full_name; String email_address; String password; String confirm_password; String deptt; Button buttton_Reg; InputStream is=null; String result=null; String line=null; int code; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.staff_reg); editText_full_name=(EditText)findViewById(R.id.editText1); editText_email_address=(EditText)findViewById(R.id.editText2); editText_password=(EditText)findViewById(R.id.editText3); editText_confirm_password=(EditText)findViewById(R.id.editText4); editText_deptt=(EditText)findViewById(R.id.editText5); Button insert=(Button)findViewById(R.id.button_Reg); insert.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { full_name=editText_full_name.getText().toString(); email_address=editText_email_address.getText().toString(); password=editText_password.getText().toString(); confirm_password=editText_confirm_password.getText().toString(); deptt=editText_deptt.getText().toString(); if ( ( !editText_full_name.getText().toString().equals()) && ( !editText_email_address.getText().toString().equals()) &&( !editText_password.getText().toString().equals())&&( !editText_confirm_password.getText().toString().equals())&&( !editText_deptt.getText().toString().equals()) ) { } else if ( ( !editText_full_name.getText().toString().equals()) ) { Toast.makeText(getApplicationContext(), Password field empty, Toast.LENGTH_SHORT).show(); } else if ( ( !editText_email_address.getText().toString().equals()) ) { Toast.makeText(getApplicationContext(), Email field empty, Toast.LENGTH_SHORT).show(); } else if( ( !editText_password.getText().toString().equals()) ) { Toast.makeText(getApplicationContext(), Password field are empty, Toast.LENGTH_SHORT).show(); } else if( ( !editText_confirm_password.getText().toString().equals()) ) { Toast.makeText(getApplicationContext(), confirm_Password field are empty, Toast.LENGTH_SHORT).show(); } else if( ( !editText_deptt.getText().toString().equals()) ) { Toast.makeText(getApplicationContext(), must enter deptt name, Toast.LENGTH_SHORT).show(); } // TODO Auto-generated method stub //if(full_name.length()>0 && email_address.length()>0 && password.length()>0 && confirm_password.length()>0 && deptt.length()>0){ // if(password.equals(confirm_password)) // { //Do Registration here //} //else //{ // Toast.makeText(getApplicationContext(), Oops! Something Went Wrong!, // Toast.LENGTH_SHORT).show(); // } // } insert(); } }); Button reset=(Button)findViewById(R.id.Reset); reset.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub EditText et=(EditText)findViewById(R.id.editText1); EditText et1=(EditText)findViewById(R.id.editText2); EditText et2=(EditText)findViewById(R.id.editText3); EditText et3=(EditText)findViewById(R.id.editText4); EditText et4=(EditText)findViewById(R.id.editText5); et.setText (); et1.setText(); et2.setText(); et3.setText(); et4.setText(); } }); } private void insert() { // TODO Auto-generated method stub ArrayList nameValuePairs = new ArrayList(); nameValuePairs.add(new BasicNameValuePair(full_name,full_name)); nameValuePairs.add(new BasicNameValuePair(email_address,email_address)); nameValuePairs.add(new BasicNameValuePair(password,password)); nameValuePairs.add(new BasicNameValuePair(confirm_password,confirm_password)); nameValuePairs.add(new BasicNameValuePair(deptt,deptt)); try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(10.0.2.2/myfolder/staff_reg.php); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); Log.e(pass 1, connection success ); } catch(Exception e) { Log.e(Fail 1, e.toString()); Toast.makeText(getApplicationContext(), net connection are not available, Toast.LENGTH_LONG).show(); } try { BufferedReader reader = new BufferedReader (new InputStreamReader(is,iso-8859-1),8); StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line + \n); } is.close(); result = sb.toString(); Log.e(pass 2, connection success ); } catch(Exception e) { Log.e(Fail 2, e.toString()); } try { JSONObject json_data = new JSONObject(result); code=(json_data.getInt(code)); if(code==1) { Toast.makeText(getBaseContext(), Inserted Successfully, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(), Sorry, Try Again, Toast.LENGTH_LONG).show(); } } catch(Exception e) { Log.e(Fail 3, e.toString()); } } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } } ........................................................................................................ dear this is my registration activity code..there is problem i this code.....first validation problem second is when i fill half form and press register button then it half values goes to database...i want that form is not sumbmitt till to complete fillig........plz any body help me
Posted on: Thu, 24 Jul 2014 11:01:30 +0000

Trending Topics



Recently Viewed Topics




© 2015