我仍然是Android编程的业余爱好者。我有一个非常讨厌的问题。当我在课堂上单击发送时它没有显示进度对话框,它也忽略了我对2个编辑文本按钮的验证。我的代码可能非常混乱和无组织。我提前道歉。
我需要做的是显示我的进度对话框运行,并在Handler结束时让它解除。此外,我需要我的敬酒表演和课程停止工作。
public class share extends Activity {
ProgressDialog dialog;
DefaultHttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://api...");
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
Button Deliver;
Deliver = (Button) findViewById (R.id.Send);
Deliver.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ProgressDialog dialog = ProgressDialog.show(share.this, "","Uploading...", true);
dialog.show();
Handler handler = new Handler();
handler.post(new Runnable() {
public void run() {
EditText etxt_user = (EditText) findViewById(R.id.user_email);
EditText etxt_pass = (EditText) findViewById(R.id.friend_email);
if(file == null){
Toast display = Toast.makeText(share.this, "There are no videos to send", Toast.LENGTH_SHORT);
display.setGravity(Gravity.BOTTOM|Gravity.LEFT, 0, 0);
display.show();
startActivity(new Intent("android.main.SHARE"));
}
else{
Pattern pattern= Pattern.compile(
"[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
"\\@" +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
"(" +"\\." + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +")+"
);
Matcher matcher=pattern.matcher(etxt_user.getText().toString());// match the contents of the first edit text
Matcher matcher1=pattern.matcher(etxt_pass.getText().toString());
if (!matcher.matches()&&(etxt_user.getText().toString()==null))
{
Toast display1 = Toast.makeText(share.this, "Please enter correct email address", Toast.LENGTH_SHORT);
display1.show();
startActivity(new Intent("com..SHARE"));
}
else
{
//proceed with program
}
if (!matcher1.matches()&&!(etxt_pass.getText().toString()==null)){
Toast display2= Toast.makeText(share.this, "You entered wrong email Format in the second box", Toast.LENGTH_LONG);
display2.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
startActivity(new Intent("com.apapa.vrsixty.SHARE"));
}
else
{
//proceed
}
try{
MultipartEntity me = new MultipartEntity();
me.addPart("file", new FileBody(new File("/sdcard/videocapture_example.H264")));
me.addPart("userEmail", new StringBody(etxt_user.getText().toString()));
me.addPart("friendEmail", new StringBody(etxt_pass.getText().toString()));
httppost.setEntity(me);
HttpResponse responsePOST = client.execute(httppost);
HttpEntity resEntity = responsePOST.getEntity();
InputStream inputstream = resEntity.getContent();
BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));
StringBuilder stringbuilder = new StringBuilder();
String currentline = null;
while ((currentline = buffered.readLine()) != null) {
stringbuilder.append(currentline + "\n");
String result = stringbuilder.toString();
Log.v("HTTP UPLOAD REQUEST",result);
inputstream.close(); } }
catch (Exception e) {
e.printStackTrace();
}
}dialog.dismiss();
}
});
}
});
当我完成此操作并按下发送后,它会给我一个没有进度对话框的黑屏,即使我对我的编辑文本进行了验证,或者如果没有要发送的文件,它只是运行程序没有停下来,露出祝酒词。提前谢谢你们
答案 0 :(得分:0)
好吧,看起来你的httppost正在将它发送到“http://”,这不是一个有效的地址,这是你问题的一部分。
另外:这个代码是逐字的吗?它无法运行。在一开始你有这条线
new HttpPost("http://"");
最后你有两个引号,这有效地使第二个引用之后的所有内容成为一个字符串,直到它遇到一个结束引用。