我正在上传字符串和照片.它的工作正常.现在我想显示进度条,同时上传数据百分比,但百分比显示很快达到100%,并花费更多时间上传,最后进入后执行方法.
protected class upload_images extends AsyncTask<String, Integer, String> {
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
// showDialog(progress_bar_type);
progressDialog = new ProgressDialog(Accept_Report.this);
progressDialog.setCancelable(false);
// dialog.setCanceledOnTouchOutside(false);
progressDialog.setIndeterminate(false);
// progressDialog.setMax(100);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// progressDialog.setProgress(0);
progressDialog.setMax(100);
// progressDialog.setMessage("Loading ...");
progressDialog.show();
// ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar2);
}
@Override
protected String doInBackground(String... params) {
URL url;
HttpURLConnection connection = null;
String http=Util.URL+"reports/media/create";
try {
url = new URL(http);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setRequestMethod("POST");
/* connection.setConnectTimeout(50000);
connection.setReadTimeout(50000);*/
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Language", "en-US");
String encoded = Base64.encodeToString(("app" …Run Code Online (Sandbox Code Playgroud) 我想将捕获的图像设置为在同一gridlayout中动态创建的imageview,但它会创建一个新的网格布局并将捕获的图像设置为新的gridview.
这是我的mainactivity.java档案
public class MainActivity extends Activity implements AdapterView.OnItemClickListener {
GridView gridView;
ArrayList<Damage_Item> gridArray = new ArrayList<Damage_Item>();
CustomAdapter_back customGridAdapter;
GridLayout mContainerView;
int REQUEST_CAMERA = 0, SELECT_FILE = 1;
ImageView dynamic_imageview;
LinearLayout dynamic_linearview;
String image1;
ArrayList<String> arrayList_image = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContainerView = (GridLayout)findViewById(R.id.describedamage_gridview) ;
//gridArray.add(new Item(homeIcon,"Home"));
gridView = (GridView) findViewById(R.id.gridview1);
Button add = (Button)findViewById(R.id.button1);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
inflateImageRow();
}
});
}
public void selectImage() { …Run Code Online (Sandbox Code Playgroud)