AsyncTaskがあります。
protected class InitTask extends AsyncTask<Context, Integer, String> {
View eachLayout;
@Override
protected String doInBackground(Context... params) {
try {
myfunction();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#onPreExecute()
*/
@Override
protected void onPreExecute() {
super.onPreExecute();
linearLayout.invalidate();
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
linearLayout.addView(eachLayout, params);
linearLayout.invalidate();
}
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#onCancelled()
*/
@Override
protected void onCancelled() {
super.onCancelled();
}
public void redrawLayout(View linearLayout) {
try {
eachLayout = linearLayout;
publishProgress();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void myFunction() {
LayoutInflater layoutInflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
params = new LinearLayout.LayoutParams(
newLinearLayout.getLayoutParams().width,
newLinearLayout.getLayoutParams().height);
for (int i = 0; i < list.size(); i++) {
final View eachLayout = layoutInflater.inflate(R.layout.sample, null);
//..........................
eachLayout.invalidate();
initTask.redrawLayout(eachLayout);
}
}
params = new LinearLayout.LayoutParams(
linearLayout.getLayoutParams().width,
linearLayout.getLayoutParams().height);
この行にIllegalStateExceptionが表示されますlinearLayout.addView(eachLayout、params); 。(この子にはすでに親がいます)。
linearLayout.removeAllViews()などを試しましたが、機能しません。
これを解決する方法は?
前もって感謝します