我正在尝试向 JSONPARSER 对象的 makeHttpRequest 添加一个参数。我觉得这与类继承有关,但没有运气。我试图让 DBURL 成为一个参数,以便我可以将数据发布到数据库。我在 Register 类上关注这个 [tutorial][1]。此外,在 onPostExecute 方法中, MainActivity.this; 将不起作用,第一个参数只有一个空值。任何想法都会很棒,如果您需要更多信息,请告诉我。
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.util.Patterns;
import android.view.KeyEvent;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity
{
private static final String DBURL = "http:/demo.php";
//obtain access to jsonparser class functions
JSONParser jsonParser = new JSONParser();
//local initialization of webview
private WebView webview;
Context context = this;
//storage of collected emails, unlimited size
ArrayList<String> emailsCollection = new ArrayList<String>();
@SuppressWarnings("rawtypes")
//to later remove duplicate arraylist items, see solution below
HashSet hashedEmails = new HashSet();
@SuppressWarnings("unchecked")
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//progress dialog message while loading app resources
final ProgressDialog pd = ProgressDialog.show(this, "", "Starting App",true);
//webview specific settings
webview = (WebView) findViewById(R.id.webview1);
webview.getSettings().setJavaScriptEnabled(true);
// webview.getSettings().setSupportZoom(true);
// webview.getSettings().setBuiltInZoomControls(true);
// webview.getSettings().setLoadWithOverviewMode(true);
// webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
//creating an instance of the webview client that supports a progress dialog
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
if(pd.isShowing()&&pd!=null)
{
pd.dismiss();
}
}
});
//url to load in the webview
webview.loadUrl("http://google.com/");
//overrides and sets title of app title bar despite original activity name
setTitle("");
}
protected void onPostExecute(String file_url)
{
if(file_url !=null)
{
Toast.makeText(null, file_url, Toast.LENGTH_LONG).show();
}
}
}