私はAsyncTask
クラスを使用してデータベースに接続しています。データに基づいて、私は動的ファイルEditText
、Checkbox
を作成し、XMLファイルは使用しません。doInBackgroundメソッドでUIまたはUIスレッドを呼び出す方法
lView = new LinearLayout(this);
- エラーが発生しました。
doInBackground
方法の内のUIスレッドをコールする方法はあります!
ありがとうございます!
@Override
protected String doInBackground(String... param) {
HashMap<String, bean> map = new HashMap<String, bean>();
try {
url = new URL("http://localhost/app/alldata.php");
} catch (MalformedURLException e) {
Toast.makeText(getApplicationContext(), "URL Exception", Toast.LENGTH_LONG).show();
e.printStackTrace();
return null;
}
try {
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("POST");
// setDoInput and setDoOutput method depict handling of both send and receive
conn.setDoInput(true);
conn.setDoOutput(true);
// Append parameters to URL
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("user_id", "user_id")
.appendQueryParameter("dpt_id","dptid");
String query = builder.build().getEncodedQuery();
// Open connection for sending data
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
conn.connect();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
int response_code = conn.getResponseCode();
lView = new LinearLayout(this);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} finally {
conn.disconnect();
}
return null;
}
本当にバックグラウンドで新しいLinearLayoutを作成する必要がありますか? 'onPostExecute'で作成することができます – JuLes