dpspn60064 2014-05-05 04:18
浏览 59
已采纳

如何使用Android EditText Data填充在线XML

I currently have an app that shows a listview of data that it gets from the internet.

Similar to the tutorial Here I am using a HTML file, and a webview right now, in order to add new data to the online XML. Like this:

<div id="stylized" class="myform">

<form action="http:site.com/test/update.php" method="GET">

    <label>Name
        <span class="small">Name of Event</span>
    </label>
<input type="text" name="title">

Now, anytime I fill in the above field "title" gets updated online by my .php script. That works flawlessly, with multiple fields.

I just want to know how I can get rid of the tacky webview. I created a custom form using editText, layouts, and buttons. But how can I use the new form to update the online XML. What is the best way to grab the data out of the editText and pass it to the <form action="http:site.com/test/update.php" method="GET"> file?

Thanks

  • 写回答

1条回答 默认 最新

  • dongsonghen9931 2014-05-05 05:51
    关注

    You can use Android's built-in Http client to send a GET request to your server.

    1. Retrieve data from EditText and process it with URLEncoder it to prepare GET request:

      String getUrl = "http://example.com/test/update.php?data=" + URLEncoder.encode(editText.getText().toString(), "UTF-8");
      
    2. Make an Http GET request using HttpURLConnection Android Http client:

      URL url = new URL(getUrl);
      HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
      
    3. Read server response.

      InputStream is = urlConnection.getInputStream();
      StringBuilder response = new StringBuilder();
      byte[] buffer = new byte[1024];
      int len = -1;
      while ((len = is.read(buffer)) != -1)
          s.append(new String(buffer, "UTF-8"));
      is.close();
      
    4. Close connection:

      urlConnection.disconnect();
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探