更新url android应用程序

时间:2012-09-12 14:23:09

标签: android

我正在创建一个应用,并希望从编辑文本中获取信息以更改网址中的api密钥

这是我到目前为止所拥有的

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://free.worldweatheronline.com/feed/weather.ashx?q=C96D62C33C38DA35E0405F0AC86017A0&format=xml&num_of_days=2&key=9e87fcbce7114648121009");

    try {
        // Add your data
        Button button1 = (Button) findViewById(R.id.send_button);
        EditText post = (EditText) findViewById(R.id.edit);

        button1.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v){

            }
        });


        HttpResponse response = httpclient.execute(httppost);

1 个答案:

答案 0 :(得分:0)

喜欢这个?按下按钮后,将使用EditText中的文本作为" api键"来执行http。希望我没有误解你......

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Add your data
    Button button1 = (Button) findViewById(R.id.send_button);
    final EditText post = (EditText) findViewById(R.id.edit);

     button1.setOnClickListener(new OnClickListener()
     {
        public void onClick(View v){
             try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://free.worldweatheronline.com/feed/weather.ashx?q=C96D62C33C38DA35E0405F0AC86017A0&format=xml&num_of_days=2&key=" + post.getText().toString());
                HttpResponse response = httpclient.execute(httppost);
             }
             ... catch etc ...
        }
     });
}

}