私が見たすべての場所で、彼らはonClickでスレッド化を使用しました。ドキュメントに記載されているように、メインスレッドでネットワーク操作を実行できないため、スレッドを使用せざるを得なくなりました。では、このようなものをコーディングしたボタンにスレッドをどのように配置しますか?
public void firstbutton(View view)
{
//some code
}
助けてくれてありがとう!
編集:
public void firstbutton(View view)
{
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
EditText editText = (EditText)findViewById(R.id.editText1);
inputMgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
EditText idnumber=(EditText)findViewById(R.id.editText1);
String idnumber2= idnumber.getText().toString();
int i = Integer.parseInt(editText.getText().toString());
idnum=i;
setContentView(R.layout.viewer);
Context context = view.getContext();
Drawable image = ImageOperations(context, WEB ADDRESS HIDDEN FOR PRIVACY"+idnumber2);
ImageView icon = new ImageView(context);
icon = (ImageView)findViewById(R.id.imageView1);
icon.setImageDrawable(image);
};
public Drawable ImageOperations(Context ctx, String url) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,IOException
{
URL url = new URL(address);
Object content = url.getContent();
return content;
}