我尝试在android中的模块中添加旋转轮进度条。但它无法正常工作。
点击发送按钮我想添加旋转轮。告诉我在哪里添加它以及如何添加。
我的代码是:
片段发送job.java
public class FragmentSendJob extends Fragment implements OnClickListener {
// this Fragment will be called from MainActivity
TextView newmember,forgot,view;
EditText uedit,pedit;
Vibrator vibe;
String euid,epass;
String name,pass;
String status_key;
private static MyDialog dialog1;
Bitmap bitmap1, bitmap2,bitmap3;
Bitmap[] bitmap;
String[] driver_details;
private byte imageInByte1[],imageInByte2[],imageInByte3[] ;
private Context mContext;
private String mname,mobile,desc;
public String advertisement_count;
private Button submit,cancel;
private EditText ename,mobno,picktime,unit,street,suburb,destination,fare,city;
private Spinner state,group;
private ViewGroup vgroup ;
// name of the para meter on send job module
private String sename,smobno,spicktime,sunit,sstreet,ssuburb,sstate, ssendjob,scity,sdestination,sfare,sgroup,login_token;
private static FragmentDialog dialog;
private SendJobDataBase db;
static final int DIALOG_ID = 0;
private Typeface ftype;
private SharedPreferences pref1,pref;
String latitude,longitude;
public String job_id;
public FragmentSendJob(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.sendjob_fragment, container, false);
pref1=this.getActivity().getSharedPreferences("LocDetails", getActivity().MODE_WORLD_READABLE);
pref=this.getActivity().getSharedPreferences("Driver", getActivity().MODE_WORLD_READABLE);
login_token=pref.getString("login_token","login_token");
latitude = pref1.getString("latitude","latitude");
longitude = pref1.getString("longitude","longitude");
ename = (EditText) rootView.findViewById(R.id.ename);
mobno = (EditText) rootView.findViewById(R.id.mobno);
picktime = (EditText) rootView.findViewById(R.id.picktime);
unit = (EditText) rootView.findViewById(R.id.unit);
street = (EditText) rootView.findViewById(R.id.street);
suburb = (EditText) rootView.findViewById(R.id.suburb);
destination = (EditText) rootView.findViewById(R.id.destination);
state = (Spinner) rootView.findViewById(R.id.state);
fare=(EditText) rootView.findViewById(R.id.fare);
group = (Spinner) rootView.findViewById(R.id.group);
city = (EditText) rootView.findViewById(R.id.city);
vgroup = (ViewGroup) rootView.findViewById(R.id.rel);
submit = (Button) rootView.findViewById(R.id.submit);
submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
new SendJob().execute();
/* Intent intent =new Intent(getActivity(),GetCurrentLocation.class);
startActivity(intent);
System.out.println(">>>>>>>>>>>>>>>>>"+latitude+"***********");
System.out.println(">>>>>>>>>>>>"+longitude+"***********");*/
}
});
cancel = (Button) rootView.findViewById(R.id.cancel);
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
for (int i = 0, count = vgroup.getChildCount(); i < count; ++i) {
View view = vgroup.getChildAt(i);
if (view instanceof EditText) {
((EditText)view).setText("");
}
}
}
});
//state spinner which represents different state by on click
String[] mystate= new String[]{"New South Wales","Victoria","Queensland","Northern Territory","Western Australia","South Australia"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), R.layout.listrow, mystate);
state.setAdapter(adapter);
state.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,int pos, long arg3) {
// TODO Auto-generated method stub
scity = state.getSelectedItem().toString();
String s1=arg0.getItemAtPosition(pos).toString();
if(s1.equals("New South Wales"))
city.setText("Sydney");
else if(s1.equals("Victoria"))
city.setText("Melbourne");
else if(s1.equals("Queensland"))
city.setText("Brisbane");
else if(s1.equals("Northern Territory"))
city.setText("Darwin");
else if(s1.equals("Western Australia"))
city.setText("Perth");
else if(s1.equals("South Australia"))
city.setText("Adelaide");
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
String[] mygroups= new String[]{"My Group","My Secondary group","Everyone"};
ArrayAdapter<String> adapters = new ArrayAdapter<String>(this.getActivity(),
R.layout.listrow, mygroups);
group.setAdapter(adapters);
group.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3) {
// TODO Auto-generated method stub
ssendjob = group.getItemAtPosition(pos).toString();
//gender.setText(setgender);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
return rootView;
}
//获取数据的Web服务
private class SendJob extends AsyncTask<String, String, String[]> {
ProgressDialog pDialog = new ProgressDialog(getActivity());
@Override
protected String[] doInBackground(final String... params)
{
ConnectivityManager conMgr = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected())
{
HttpClient httpclient = new DefaultHttpClient();
try
{
System.out.print("***** login token *****"+login_token);
JSONObject job= new JSONObject();
sename = ename.getText().toString();
smobno = mobno.getText().toString();
spicktime = picktime.getText().toString();
sunit = unit.getText().toString();
sstreet = street.getText().toString();
ssuburb = suburb.getText().toString();
sstate = state.getSelectedItem().toString();
scity = city.getText().toString();
sdestination = destination.getText().toString();
sgroup = group.getSelectedItem().toString();
sfare = fare.getText().toString();
sename.replace("" ,"%20");
smobno.replace("" ,"%20");
spicktime.replace("" ,"%20");
sunit.replace("" ,"%20");
sstreet.replace("" ,"%20");
sstate.replace("" ,"%20");
ssuburb.replace("" ,"%20");
scity.replace("" ,"%20");
sdestination.replace("" ,"%20");
sgroup.replace("" ,"%20");
sfare.replace("" ,"%20");
job.put("name",sename);
job.put("mobile_no",smobno);
job.put("pickup_time",spicktime);
job.put("unit_no",sunit);
job.put("street_name",sstreet);
job.put("state",sstate);
job.put("suburb",ssuburb);
job.put("city",scity);
job.put("destination",sdestination);
job.put("group",sgroup);
job.put("fare",sfare);
job.put("latitude",latitude);
job.put("longitude",longitude);
job.put("status_key","2");
job.put("method","send_job");
job.put("login_token",login_token);
StringEntity se = new StringEntity(job.toString());
HttpPost httppost = new HttpPost("http://suntechwebsolutions.com/clients/mobileapp_now/webservice.php");
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
String data = EntityUtils.toString(response.getEntity());
Log.i("response", data);
System.out.println("response "+data);
String call;
call = data;
System.out.println("print me............."+call);
JSONObject jo = new JSONObject(data);
Log.d("response", jo.toString(4));
/*JSONObject jobId= jo.getJSONObject("id");
job_id=jobId.getString("id");*/
if(jo.getString("err-code").equals("0"))
{
DatabaseAdmin admin = new DatabaseAdmin(getActivity());
try
{
admin.insert_user(smobno, sename, smobno, sdestination, sstate, "0", spicktime, sunit, sstreet, ssuburb, scity, sfare, sgroup);
}
catch(Exception e)
{
e.printStackTrace();
}
final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Alert!!!");
alert.setMessage(jo.getString("message"));
alert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
pDialog.dismiss();
dialog.dismiss();
/* Intent intent =new Intent(getActivity(),HandleData.class);
intent.putExtra("pickupsuburb", ssuburb);
intent.putExtra("destination", sdestination);
startActivity(intent);*/
}
});
getActivity().runOnUiThread(new Runnable() {
public void run() {
alert.show();
}
});
}
else
{
final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Alert !");
alert.setMessage(jo.getString("message"));
alert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
});
getActivity().runOnUiThread(new Runnable()
{
public void run()
{
pDialog.dismiss();
alert.show();
}
});
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
else
{
final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Alert !");
alert.setMessage("No Internet connection ");
alert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
dialog.dismiss();
}
});
getActivity().runOnUiThread(new Runnable()
{
public void run()
{
pDialog.dismiss();
alert.show();
}
});
}
return params;
}
@Override
protected void onPostExecute(String[] result)
{
super.onPostExecute(result);
}
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:1)
我认为你遗忘了.show()
Progress Dialog
pDialog.show();
并在pDialog
中的onPreExecute()
中实施AsyncTask
,就像这样,
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage("Loading please wait....");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
和dismiss Progress Dialog
中的onPostExecute(....)
就像这样,
@Override
protected void onPostExecute(String[] result)
{
super.onPostExecute(result);
pDialog.dismiss();
}