主要活动中有2个文本框,ed1
和ed2
以及保存按钮。
final EditText ed1 = (EditText)findViewById(R.id.location_address);
final EditText ed2 = (EditText)findViewById(R.id.workername);
public void postData() {
String fullUrl = "https://docs.google.com/forms/d/e/1FAIpQLSe5WZB-e95xrx3ZbwiOWtJx3wEuT-fJw/formResponse";
HttpRequest mReq = new HttpRequest();
String data = "entry.748835646=" + URLEncoder.encode(location) + "&" +
"entry.481985278=" + URLEncoder.encode(name);
String response = mReq.sendPost(fullUrl, data);
Log.i(myTag, response);
}
我没有得到为String数据上面的2个edittexts写的内容。
如何编写ed1
和ed2
的代码,以便在用户输入ed1
和ed1
后,点击“保存”按钮,数据会保存到Google形成? (即执行postData
方法)
答案 0 :(得分:1)
public void postData() {
String fullUrl = "https://docs.google.com/forms/d/e/1FAIpQLSe5WZB-e95xrx3ZbwiOWtJx3wEuT-fJw/formResponse";
HttpRequest mReq = new HttpRequest();
String data = "entry.748835646=" + URLEncoder.encode(ed1.getText().toString()) + "&" +
"entry.481985278=" + URLEncoder.encode(ed2.getText().toString());
String response = mReq.sendPost(fullUrl, data);
Log.i(myTag, response);
}
答案 1 :(得分:0)
我自己解决了这个问题:
修改后的postData()方法如下: -
public void postData(){
String fullUrl = "https://docs.google.com/forms/d/e/1FAIpQLSe5WZbIwv6m5uqf2Z73Uh7B-e95xrx3ZbEuT-fJw/formResponse";
HttpRequest mReq = new HttpRequest();
final EditText ed1 = (EditText)findViewById(R.id.location_address);
final EditText ed2 = (EditText)findViewById(R.id.workername);
location=ed1.getText().toString();
name=ed2.getText().toString();
String data = "entry.748835646=" + URLEncoder.encode(location) + "&" +
"entry.481985278=" + URLEncoder.encode(name);
String response = mReq.sendPost(fullUrl, data);
Log.i(myTag, response);
}