rohan kumar

rohan kumar

  • NA
  • 1
  • 746

problem with Spinner value

Feb 3 2016 11:18 PM
\\this is my register.java code:
`public class Register extends Activity {
TextView ET_DEPARTMENT;
Spinner ET_TYPE;
EditText ET_NAME,ET_USER_NAME,ET_USER_PASS,ET_MOBILE,ET_PIN;
String name,type,user_name,user_pass,department,mobile,pin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register_layout);
ET_NAME=(EditText)findViewById(R.id.name);
final Spinner ET_TYPE= (Spinner)findViewById(R.id.automobileSpinner);
ET_USER_NAME=(EditText)findViewById(R.id.new_user_name);
ET_USER_PASS=(EditText)findViewById(R.id.new_user_pass);
ET_DEPARTMENT=(TextView)findViewById(R.id.RegistrationForm);
ET_MOBILE=(EditText)findViewById(R.id.user_mobile);
ET_PIN=(EditText)findViewById(R.id.user_pin);
}
public void userReg(View view)
{
name=ET_NAME.getText().toString();
type=ET_TYPE.getSelectedItem().toString();
user_name=ET_USER_NAME.getText().toString();
user_pass=ET_USER_PASS.getText().toString();
department=ET_DEPARTMENT.getText().toString();
mobile=ET_MOBILE.getText().toString();
pin=ET_PIN.getText().toString();
String method="register";
BackgroundTask backgroundTask=new BackgroundTask(this);
backgroundTask.execute(method,name,user_name,user_pass,department,mobile,pin);
finish();
}
}
this is my backgroundTask.java code:
enter code here
public class BackgroundTask extends AsyncTask<String,Void,String> {
Context ctx;
BackgroundTask(Context ctx)
{
this.ctx=ctx;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String reg_url="http://10.0.2.2/handy/register.php";
String method=params[0];
if (method.equals("register"))
{
String name=params[1];
String user_name=params[2];
String user_pass=params[3];
String department=params[4];
String mobile=params[5];
String pin=params[6];
String type=params[7];
try {
URL url=new URL(reg_url);
HttpURLConnection httpURLConnection=(HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream OS=httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(OS,"UTF-8"));
String data= URLEncoder.encode("user","UTF-8") +"="+URLEncoder.encode(name,"UTF-8")+"&"+
URLEncoder.encode("user_name","UTF-8") +"="+URLEncoder.encode(user_name,"UTF-8")+"&"+
URLEncoder.encode("user_pass","UTF-8") +"="+URLEncoder.encode(user_pass,"UTF-8")+"&"+
URLEncoder.encode("department","UTF-8") +"="+URLEncoder.encode(department,"UTF-8")+"&"+
URLEncoder.encode("mobile","UTF-8") +"="+URLEncoder.encode(mobile,"UTF-8")+"&"+
URLEncoder.encode("pin","UTF-8") +"="+URLEncoder.encode(pin,"UTF-8")+"&"+
URLEncoder.encode("type","UTF-8") +"="+ URLEncoder.encode(type,"UTF-8");
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
OS.close();
InputStream IS=httpURLConnection.getInputStream();
IS.close();
return "Registration Success...";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(ctx,result,Toast.LENGTH_LONG).show();
}
}
this is my layout file as register.xml:
enter code here
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0BB990"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration Form"
android:textAppearance="?android:textAppearanceLarge"
android:textStyle="bold"
android:id="@+id/RegistrationForm"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Name"
android:ems="10"
android:id="@+id/name"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="User Name"
android:id="@+id/new_user_name"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Password"
android:id="@+id/new_user_pass"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:inputType="textPassword"/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Mobile"
android:inputType="phone"
android:layout_marginTop="20dp"
android:ems="10"
android:id="@+id/user_mobile"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:hint="Pin-Code"
android:layout_marginTop="10dp"
android:ems="10"
android:id="@+id/user_pin"
android:layout_gravity="center_horizontal" />
<Spinner
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="@+id/automobileSpinner"
android:entries="@array/automobile_type"
android:layout_below="@+id/textView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_alignParentStart="true"
/>
<Button
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="Register"
android:id="@+id/button"
android:layout_gravity="center_horizontal"
android:layout_marginTop="80dp"
android:onClick="userReg"
/>
this is my php code to insert into mysql:
enter code here
<?php
require"connection.php";
$id=$_POST[""];
$name=$_POST["user"];
$user_name=$_POST["user_name"];
$user_pass=$_POST["user_pass"];
$department=$_POST["department"];
$date=$_POST[""];
$mobile=$_POST["mobile"];
$pin=$_POST["pin"];
$type=$_POST["type"]
$sql_query="insert into user_info
(id,name,user_name,user_pass,department,mobile,pin,type
)
values
('$id','$name','$user_name','$user_pass','$department',
'$mobile','$pin','type');";
if(mysqli_query($con,$sql_query))
{
//echo"<h3>Data Insertion Success</h3>";
}
else
{
//echo"Data insertion error...".mysqli_error($con);
}
?>