我有两个单选按钮,可以选择男性或女性。我的要求是,如果我点击male
单选按钮,我必须向服务器发送数字1
,如果我点击female
单选按钮,我必须向服务器发送数字2
(在服务器端,他们用这个数字进行检查。也就是说,如果他们收到1,那么它是男性,如果他们收到“2”,那么它是女性)服务器端然后相应地给出1或2的响应
。所以这里我必须检查我是否得到1作为响应,我必须将男性设置为性别
,如果响应是2,我必须将女性设置为性别
。我该怎么做?
public class MainActivity extends Activity implements AsyncResponse,AsyncResponse2 {
EditText fullname,gender,city,mobileno;
TextView originalname,reviewNumber;
//for displaying in textfield before entering values(when loading)
private static final String TAG_NAME = "fullname";
private static final String TAG_GENDER = "gender";
private static final String TAG_CITY = "city_name";
private static final String TAG_PHNO = "phone_number";
private static final String TAG_REVIEWNUM = "revcount";
RadioButton male,female;
String numberToPass = "1" ;//default 1 for male
//str photo upload
ImageView imageView1, imageView2;
//RoundImage roundedImage, roundedImage1;
//private static int RESULT_LOAD_IMAGE = 1; //added
//end photo upload
Button submit;
//str round img upload
CircularBitmap c= new CircularBitmap();
Button pic;
String selectedImagePath;
ImageView image;
//end round img upload
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//str photo upload
pic = (Button)findViewById(R.id.button1);
image = (ImageView)findViewById(R.id.imageView1);
//this the button which allows you to access the gallery
pic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gallery();
}
});
//end photo upload
fullname=(EditText)findViewById(R.id.nameid);
// gender=(EditText)findViewById(R.id.genderid);
male=(RadioButton)findViewById(R.id.maleid);
female=(RadioButton)findViewById(R.id.femaleid);
city=(EditText)findViewById(R.id.cityid);
mobileno=(EditText)findViewById(R.id.mobileid);
originalname=(TextView)findViewById(R.id.originalnameid);//original name title
reviewNumber=(TextView)findViewById(R.id.reviewNum);
submit=(Button)findViewById(R.id.submitid);
//to display fullname,gender,city,moblieno while loading(so outside buttonclick)
String key1 = "saasvaap123";
String signupid1 = "8";
String url2 = "http://gooffers.in/omowebservices/index.php/webservice/Public_User/get_user_profile?";
//put the below lines outside button onclick since we load the values into edittext when opening the app
CustomHttpClient2 task2 = new CustomHttpClient2();
task2.execute(url2,key1,signupid1);
task2.delegate = MainActivity.this;
//to send values on button click
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String fullname1= fullname.getText().toString();
// String gender1= gender.getText().toString();
String city1= city.getText().toString();
String mobileno1= mobileno.getText().toString();
String key1 = "saasvaap123";
String signupid1 = "3";
// String cityid1 = "3";
String originalname1= originalname.getText().toString();
// onRadioButtonClicked(numberToPasss);
String url = "http://gooffers.in/omowebservices/index.php/webservice/Public_User/edit_user_profile?";
CustomHttpClient task = new CustomHttpClient();
task.execute(url,key1,signupid1,numberToPass,mobileno1,fullname1,city1);
task.delegate = MainActivity.this;
//mobile number validation
if (!isValidMobNum(mobileno1)) {
mobileno.setError("Enter valid mobile number!");
}
// key=saasvaap123&signup_id=3&gender=1&phone_number=1234567890&fullname=saas&city_id=3
}
});
} //close oncreate
public void onRadioButtonClicked(View v) {
switch (v.getId()) {
case R.id.maleid:
numberToPass = "1";
break;
case R.id.femaleid:
numberToPass = "2";
break;
}
}
//str img upload
//this allows you select one image from gallery
public void gallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
}
//when starting activity for result and choose an image, the code will automatically continue here
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Uri current_ImageURI = data.getData();
selectedImagePath = getPath(current_ImageURI);
image.setImageBitmap(c.circle(decodeSampledBitmap(new File(selectedImagePath), 400, 400),Color.rgb(255,255,255)));
}
}
}
public String getPath(Uri contentUri) {
// we have to check for sdk version because from lollipop the retrieval of path is different
if (Build.VERSION.SDK_INT < 21) {
// can post image
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = getApplicationContext().getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else {
String filePath = "";
String wholeID = DocumentsContract.getDocumentId(contentUri);
// Split at colon, use second item in the array
String id = wholeID.split(":")[1];
String[] column = {MediaStore.Images.Media.DATA};
// where id is equal to
String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,column, sel, new String[]{id}, null);
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
}
cursor.close();
return filePath;
}
}
public Bitmap decodeSampledBitmap(File res, int reqWidth, int reqHeight) {
if (res != null) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
FileInputStream stream2 = new FileInputStream(res);
BitmapFactory.decodeStream(stream2, null, options);
stream2.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Calculate inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
o2.inJustDecodeBounds = false;
FileInputStream stream = null;
try {
stream = new FileInputStream(res);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, o2);
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
} else
return null;
}
public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
//end img upload
//validating mobile num
private boolean isValidMobNum(String mobileno1) {
String MobilePattern = "[0-9]{10,13}"; //can enter upto 13 digits-change here if we need to increase the range of digits
if(mobileno.getText().toString().matches(MobilePattern))
{
Toast.makeText(getApplicationContext(), "phone number is valid",
Toast.LENGTH_SHORT).show();
return true;
}
else if(!mobileno.getText().toString().matches(MobilePattern))
{
Toast.makeText(getApplicationContext(), "Please enter valid 10 digit phone number", Toast.LENGTH_SHORT).show();
return false;
}
return false;
}
//str if empty validation
// if(fullname1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your name!", Toast.LENGTH_SHORT).show();
// }
// else if(gender1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your gender!", Toast.LENGTH_SHORT).show();
// }
// else if(city1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your city name!", Toast.LENGTH_SHORT).show();
// }
// else if(mobileno1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your contact number!", Toast.LENGTH_SHORT).show();
// }
// else
// {
// Toast.makeText(MainActivity.this,"ok!", Toast.LENGTH_SHORT).show();
// }
// //end if empty validation
//edit
private class CustomHttpClient extends AsyncTask<String, String, String>{
public AsyncResponse delegate=null;
private String msg;
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
delegate.processFinish(result);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
if(params == null) return null;
// get url from params
String url = params[0];
String key1 = params[1];
String signupid1 = params[2];
String gender1 = params[3];
String mobileno1 = params[4];
String fullname1 = params[5];
String city1 = params[6];
//key=saasvaap123&signup_id=3&gender=1&phone_number=1234567890&fullname=saas&city_id=3
ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("fullname",fullname1));
postParameters.add(new BasicNameValuePair("gender",gender1));
postParameters.add(new BasicNameValuePair("city_name",city1));
postParameters.add(new BasicNameValuePair("phone_number",mobileno1));
postParameters.add(new BasicNameValuePair("key",key1));
postParameters.add(new BasicNameValuePair("signup_id",signupid1));
// //str
try {
// create http connection
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
// connect
HttpResponse response = client.execute(httppost);
// get response
HttpEntity entity = response.getEntity();
if(entity != null){
return EntityUtils.toString(entity);
}
else{
return "No string.";
}
}
catch(Exception e){
return "Network problem";
}
}
}
public void processFinish (String output){
Toast.makeText(MainActivity.this,output, Toast.LENGTH_SHORT).show();
try{
JSONObject json=new JSONObject(output);
// Integer success = json.getInt(SUCCESS);
String msg = json.getString("message");
// String Status = json.getString("status");
// String userid = json.getString("userid");
// String usertype = json.getString("usertype");
// Integer userid=json.getInt("userid");
// String User_ID=String.valueOf(userid);
// SharedPreferences sharedpreferences = getSharedPreferences(AQUASAN, Context.MODE_PRIVATE);
// Editor editor = sharedpreferences.edit();
// editor.putString("ID", Employee_ID);
// editor.commit();
//needed
// String fullname = nameid.setText("saas");
// String gender = genderid.setText("0");
// String city_id = cityid.setText("0");
// String phone_number = mobileid.setText("0");
String a="Successfully Updated";
if(msg.compareTo(a)==0){
Toast.makeText(MainActivity.this,"Your profile has been successfully updated!", Toast.LENGTH_SHORT).show();
// Toast.makeText(MainActivity.this,msg, Toast.LENGTH_SHORT).show();
// startActivity(new Intent(Login.this, HomeScreen.class));
}
else{
Toast.makeText(MainActivity.this,"Please enter the details correctly!", Toast.LENGTH_SHORT).show();
}
}catch (JSONException e) {
}
}
//edit
//str customhttp2
private class CustomHttpClient2 extends AsyncTask<String, String, String>{
public AsyncResponse2 delegate=null;
private String msg;
@Override
protected void onPostExecute(String result2) {
// TODO Auto-generated method stub
super.onPostExecute(result2);
delegate.processFinish2(result2);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
// fullname=(EditText)findViewById(R.id.nameid);
// gender=(EditText)findViewById(R.id.genderid);
// city=(EditText)findViewById(R.id.cityid);
// mobileno=(EditText)findViewById(R.id.mobileid);
}
@Override
protected String doInBackground(String... params) {
if(params == null) return null;
// get url from params
String url2 = params[0];
String key1 = params[1];
String signupid1 = params[2];
// String gender1 = params[3];
// String mobileno1 = params[4];
// String fullname1 = params[5];
// String city1 = params[6];
//key=saasvaap123&signup_id=3&gender=1&phone_number=1234567890&fullname=saas&city_id=3
ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<NameValuePair>();
// postParameters.add(new BasicNameValuePair("fullname",fullname1));
// postParameters.add(new BasicNameValuePair("gender",gender1));
// postParameters.add(new BasicNameValuePair("city_id",city1));
// postParameters.add(new BasicNameValuePair("phone_number",mobileno1));
postParameters.add(new BasicNameValuePair("key",key1));
postParameters.add(new BasicNameValuePair("signup_id",signupid1));
try {
// create http connection
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url2);
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
// connect
HttpResponse response = client.execute(httppost);
// get response
HttpEntity entity = response.getEntity();
if(entity != null){
return EntityUtils.toString(entity);
}
else{
return "No string.";
}
}
catch(Exception e){
return "Network problem";
}
}
}
public void processFinish2 (String output2){
Toast.makeText(MainActivity.this,output2, Toast.LENGTH_SHORT).show();
try{
JSONObject jsonResponse=new JSONObject(output2);
JSONArray aJson = jsonResponse.getJSONArray("profile");
// Integer success = json.getInt(SUCCESS);
// String msg = json.getString("message");
for(int i=0; i<aJson.length(); i++) {
JSONObject json = aJson.getJSONObject(i);
//str
String strName = json.getString(TAG_NAME);
String strGender = json.getString(TAG_GENDER);
String strCity = json.getString(TAG_CITY);
String strPhNo = json.getString(TAG_PHNO);
String strOriginalName = json.getString(TAG_NAME);
String strreviewNumber = json.getString(TAG_REVIEWNUM);
fullname.setText(strName);
// gender.setText(strGender);
city.setText(strCity);
mobileno.setText(strPhNo);
originalname.setText(strOriginalName);
reviewNumber.setText(strreviewNumber+"Reviews");//setting name to original name text-displayed while loading
Toast.makeText(MainActivity.this,strGender, Toast.LENGTH_SHORT).show();
//end
}
}catch (JSONException e) {
Toast.makeText(MainActivity.this,"Exception caught!", Toast.LENGTH_SHORT).show();
}
}
}
你在课堂上有参考按钮。
String numberToPass = "1" //default 1 for male
RadioGroup rg = (RadioGroup) findViewById(R.id.user_gender);
RadioButton gender_radio_male = (RadioButton) findViewById(R.id.radioMale);
RadioButton gender_radio_female = (RadioButton) findViewById(R.id.radioFemale);
必须在类中添加onRadioButtonClicked()方法
public void onRadioButtonClicked(View v) {
switch (v.getId()) {
case R.id.radioMale:
numberToPass = "1";
break;
case R.id.radioFemale:
numberToPass = "2";
break;
}
}
编辑:
代码:
public class MainActivity extends Activity implements AsyncResponse,AsyncResponse2 {
EditText fullname,gender,city,mobileno;
TextView originalname,reviewNumber;
//for displaying in textfield before entering values(when loading)
private static final String TAG_NAME = "fullname";
private static final String TAG_GENDER = "gender";
private static final String TAG_CITY = "city_name";
private static final String TAG_PHNO = "phone_number";
private static final String TAG_REVIEWNUM = "revcount";
RadioButton male,female;
String numberToPass = "1" ;//default 1 for male
//str photo upload
ImageView imageView1, imageView2;
//RoundImage roundedImage, roundedImage1;
//private static int RESULT_LOAD_IMAGE = 1; //added
//end photo upload
Button submit;
//str round img upload
CircularBitmap c= new CircularBitmap();
Button pic;
String selectedImagePath;
ImageView image;
//end round img upload
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//str photo upload
pic = (Button)findViewById(R.id.button1);
image = (ImageView)findViewById(R.id.imageView1);
//this the button which allows you to access the gallery
pic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gallery();
}
});
//end photo upload
fullname=(EditText)findViewById(R.id.nameid);
// gender=(EditText)findViewById(R.id.genderid);
male=(RadioButton)findViewById(R.id.maleid);
female=(RadioButton)findViewById(R.id.femaleid);
city=(EditText)findViewById(R.id.cityid);
mobileno=(EditText)findViewById(R.id.mobileid);
originalname=(TextView)findViewById(R.id.originalnameid);//original name title
reviewNumber=(TextView)findViewById(R.id.reviewNum);
submit=(Button)findViewById(R.id.submitid);
//to display fullname,gender,city,moblieno while loading(so outside buttonclick)
String key1 = "saasvaap123";
String signupid1 = "8";
String url2 = "http://gooffers.in/omowebservices/index.php/webservice/Public_User/get_user_profile?";
//put the below lines outside button onclick since we load the values into edittext when opening the app
CustomHttpClient2 task2 = new CustomHttpClient2();
task2.execute(url2,key1,signupid1);
task2.delegate = MainActivity.this;
//to send values on button click
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String fullname1= fullname.getText().toString();
String gender1= gender.getText().toString();
String city1= city.getText().toString();
String mobileno1= mobileno.getText().toString();
String key1 = "saasvaap123";
String signupid1 = "3";
// String cityid1 = "3";
//// //str if empty validation
// if(fullname==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your name!", Toast.LENGTH_SHORT).show();
// }
// else if(gender1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your gender!", Toast.LENGTH_SHORT).show();
// }
// else if(city==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your city name!", Toast.LENGTH_SHORT).show();
// }
// else if(mobileno==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your contact number!", Toast.LENGTH_SHORT).show();
// }
// else
// {
// Toast.makeText(MainActivity.this,"ok!", Toast.LENGTH_SHORT).show();
// }
// // //end if empty validation
//// //end if empty validation
////
String originalname1= originalname.getText().toString();
String url = "http://gooffers.in/omowebservices/index.php/webservice/Public_User/edit_user_profile?";
CustomHttpClient task = new CustomHttpClient();
task.execute(url,key1,signupid1,gender1,mobileno1,fullname1,city1);
task.delegate = MainActivity.this;
//mobile number validation
if (!isValidMobNum(mobileno1)) {
mobileno.setError("Enter valid mobile number!");
}
// key=saasvaap123&signup_id=3&gender=1&phone_number=1234567890&fullname=saas&city_id=3
}
});
} //close oncreate
public void onRadioButtonClicked(View v) {
switch (v.getId()) {
case R.id.radioMale:
numberToPass = "1";
break;
case R.id.radioFemale:
numberToPass = "2";
break;
}
}
//str img upload
//this allows you select one image from gallery
public void gallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
}
//when starting activity for result and choose an image, the code will automatically continue here
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
Uri current_ImageURI = data.getData();
selectedImagePath = getPath(current_ImageURI);
image.setImageBitmap(c.circle(decodeSampledBitmap(new File(selectedImagePath), 400, 400),Color.rgb(255,255,255)));
}
}
}
public String getPath(Uri contentUri) {
// we have to check for sdk version because from lollipop the retrieval of path is different
if (Build.VERSION.SDK_INT < 21) {
// can post image
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = getApplicationContext().getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else {
String filePath = "";
String wholeID = DocumentsContract.getDocumentId(contentUri);
// Split at colon, use second item in the array
String id = wholeID.split(":")[1];
String[] column = {MediaStore.Images.Media.DATA};
// where id is equal to
String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,column, sel, new String[]{id}, null);
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
}
cursor.close();
return filePath;
}
}
public Bitmap decodeSampledBitmap(File res, int reqWidth, int reqHeight) {
if (res != null) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
FileInputStream stream2 = new FileInputStream(res);
BitmapFactory.decodeStream(stream2, null, options);
stream2.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Calculate inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
o2.inJustDecodeBounds = false;
FileInputStream stream = null;
try {
stream = new FileInputStream(res);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, o2);
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
} else
return null;
}
public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
//end img upload
//validating mobile num
private boolean isValidMobNum(String mobileno1) {
String MobilePattern = "[0-9]{10,13}"; //can enter upto 13 digits-change here if we need to increase the range of digits
if(mobileno.getText().toString().matches(MobilePattern))
{
Toast.makeText(getApplicationContext(), "phone number is valid",
Toast.LENGTH_SHORT).show();
return true;
}
else if(!mobileno.getText().toString().matches(MobilePattern))
{
Toast.makeText(getApplicationContext(), "Please enter valid 10 digit phone number", Toast.LENGTH_SHORT).show();
return false;
}
return false;
}
//str if empty validation
// if(fullname1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your name!", Toast.LENGTH_SHORT).show();
// }
// else if(gender1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your gender!", Toast.LENGTH_SHORT).show();
// }
// else if(city1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your city name!", Toast.LENGTH_SHORT).show();
// }
// else if(mobileno1==null)
// {
// Toast.makeText(MainActivity.this,"Please enter your contact number!", Toast.LENGTH_SHORT).show();
// }
// else
// {
// Toast.makeText(MainActivity.this,"ok!", Toast.LENGTH_SHORT).show();
// }
// //end if empty validation
//edit
private class CustomHttpClient extends AsyncTask<String, String, String>{
public AsyncResponse delegate=null;
private String msg;
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
delegate.processFinish(result);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
if(params == null) return null;
// get url from params
String url = params[0];
String key1 = params[1];
String signupid1 = params[2];
String gender1 = params[3];
String mobileno1 = params[4];
String fullname1 = params[5];
String city1 = params[6];
//key=saasvaap123&signup_id=3&gender=1&phone_number=1234567890&fullname=saas&city_id=3
ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("fullname",fullname1));
postParameters.add(new BasicNameValuePair("gender",gender1));
postParameters.add(new BasicNameValuePair("city_name",city1));
postParameters.add(new BasicNameValuePair("phone_number",mobileno1));
postParameters.add(new BasicNameValuePair("key",key1));
postParameters.add(new BasicNameValuePair("signup_id",signupid1));
// //str
try {
// create http connection
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
// connect
HttpResponse response = client.execute(httppost);
// get response
HttpEntity entity = response.getEntity();
if(entity != null){
return EntityUtils.toString(entity);
}
else{
return "No string.";
}
}
catch(Exception e){
return "Network problem";
}
}
}
public void processFinish (String output){
Toast.makeText(MainActivity.this,output, Toast.LENGTH_SHORT).show();
try{
JSONObject json=new JSONObject(output);
// Integer success = json.getInt(SUCCESS);
String msg = json.getString("message");
// String Status = json.getString("status");
// String userid = json.getString("userid");
// String usertype = json.getString("usertype");
// Integer userid=json.getInt("userid");
// String User_ID=String.valueOf(userid);
// SharedPreferences sharedpreferences = getSharedPreferences(AQUASAN, Context.MODE_PRIVATE);
// Editor editor = sharedpreferences.edit();
// editor.putString("ID", Employee_ID);
// editor.commit();
//needed
// String fullname = nameid.setText("saas");
// String gender = genderid.setText("0");
// String city_id = cityid.setText("0");
// String phone_number = mobileid.setText("0");
String a="Successfully Updated";
if(msg.compareTo(a)==0){
Toast.makeText(MainActivity.this,"Your profile has been successfully updated!", Toast.LENGTH_SHORT).show();
// Toast.makeText(MainActivity.this,msg, Toast.LENGTH_SHORT).show();
// startActivity(new Intent(Login.this, HomeScreen.class));
}
else{
Toast.makeText(MainActivity.this,"Please enter the details correctly!", Toast.LENGTH_SHORT).show();
}
}catch (JSONException e) {
}
}
//edit
//str customhttp2
private class CustomHttpClient2 extends AsyncTask<String, String, String>{
public AsyncResponse2 delegate=null;
private String msg;
@Override
protected void onPostExecute(String result2) {
// TODO Auto-generated method stub
super.onPostExecute(result2);
delegate.processFinish2(result2);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
// fullname=(EditText)findViewById(R.id.nameid);
// gender=(EditText)findViewById(R.id.genderid);
// city=(EditText)findViewById(R.id.cityid);
// mobileno=(EditText)findViewById(R.id.mobileid);
}
@Override
protected String doInBackground(String... params) {
if(params == null) return null;
// get url from params
String url2 = params[0];
String key1 = params[1];
String signupid1 = params[2];
// String gender1 = params[3];
// String mobileno1 = params[4];
// String fullname1 = params[5];
// String city1 = params[6];
//key=saasvaap123&signup_id=3&gender=1&phone_number=1234567890&fullname=saas&city_id=3
ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<NameValuePair>();
// postParameters.add(new BasicNameValuePair("fullname",fullname1));
// postParameters.add(new BasicNameValuePair("gender",gender1));
// postParameters.add(new BasicNameValuePair("city_id",city1));
// postParameters.add(new BasicNameValuePair("phone_number",mobileno1));
postParameters.add(new BasicNameValuePair("key",key1));
postParameters.add(new BasicNameValuePair("signup_id",signupid1));
try {
// create http connection
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url2);
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
// connect
HttpResponse response = client.execute(httppost);
// get response
HttpEntity entity = response.getEntity();
if(entity != null){
return EntityUtils.toString(entity);
}
else{
return "No string.";
}
}
catch(Exception e){
return "Network problem";
}
}
}
public void processFinish2 (String output2){
Toast.makeText(MainActivity.this,output2, Toast.LENGTH_SHORT).show();
try{
JSONObject jsonResponse=new JSONObject(output2);
JSONArray aJson = jsonResponse.getJSONArray("profile");
// Integer success = json.getInt(SUCCESS);
// String msg = json.getString("message");
for(int i=0; i<aJson.length(); i++) {
JSONObject json = aJson.getJSONObject(i);
//str
String strName = json.getString(TAG_NAME);
String strGender = json.getString(TAG_GENDER);
String strCity = json.getString(TAG_CITY);
String strPhNo = json.getString(TAG_PHNO);
String strOriginalName = json.getString(TAG_NAME);
String strreviewNumber = json.getString(TAG_REVIEWNUM);
fullname.setText(strName);
gender.setText(strGender);
city.setText(strCity);
mobileno.setText(strPhNo);
originalname.setText(strOriginalName);
reviewNumber.setText(strreviewNumber+"Reviews");//setting name to original name text-displayed while loading
Toast.makeText(MainActivity.this,strGender, Toast.LENGTH_SHORT).show();
//end
}
}catch (JSONException e) {
Toast.makeText(MainActivity.this,"Exception caught!", Toast.LENGTH_SHORT).show();
}
}
}
我希望它有帮助!
问题内容: 我知道,当您使用单选按钮时,如果要使用数字,则需要将变量设置为IntVar()。不幸的是,我在下面运行的代码带有以下错误: 有谁知道为什么会这样?我想做的是通过使用单选按钮更改加载到pygame中的图像 问题答案: 您需要在创建对象之前创建根窗口小部件。 调整代码以首先创建根窗口小部件:
我有这个数据框架,我想知道谁在每个城市获得了最高分。 到目前为止,我已经尝试过了,但这给了我每个城市的男性和女性的顶尖人物, 我想要一个在每个城市得分最高的候选人[男性或女性]。
所以假设我有一个“开”和一个“关”按钮。当我按下打开按钮时,我希望打开按钮隐藏自己,关闭按钮显示出来,反之亦然。 一个人怎么能这么做?
我有一个表单,它有一组单选按钮,我正在用php将选中按钮的值发送到另一个页面。表单具有添加另一组相同单选按钮的选项,所以如果我使用以下给出name属性的方法: 并添加上述的克隆, 这将给我每个输入的值,这将总共4。我试图使用括号递增方法,但仍保留返回选中的单选按钮值的功能。 所以我的问题是,有没有一种方法可以使用方括号对name属性进行自动递增,但是当将值发送到php时,确保每个div单选按钮分组
我是网络编程的新手,我真的需要你的帮助。我有一个带有几个单选按钮的表单,我想通过一个ajax帖子将它们插入mysql。我可以为一个按钮,但为多个,我不知道如何做。 这是我的html和jQuery的一部分: 下面是我在MySQL中插入按钮的方法: 我尝试为每个按钮创建一个var,但没有成功。我如何在php中发布所有的值,我应该在我的ajax和php中改变什么?谢谢! 这就是我执行.php的方法
我想在我的应用程序中放两个单选按钮(男性和女性)。 我是用单选按钮(不是组)来实现的,但问题是:一个按钮不能被取消选中,也可以同时检查两个按钮 RadioButton group是一组三个按钮,我只需要两个。有没有办法让他们成为两个人? 有什么帮助吗?