0

アプリを作成していますが、編集テキストから情報を取得して、URLの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);
4

1 に答える 1

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 ...
        }
     });
}

}

于 2012-09-12T14:28:01.683 に答える