我的问题是:为什么,如果我使用的LinearLayout,而不是Object ,作为我的“结果” AsyncTask ( TableWithinExpListTask中给我许多错误,如无法实例类型的LinearLayout?
在我看来,它并不能识别LinearLayout在了createFormattedCell()我不能undertstand原因。
在AsyncTask声明LinearLayout有黄色下划线和Eclipse说: 类型参数的LinearLayout是隐藏式的LinearLayout。
请有人可以解释这样对我?
下面是类的代码:
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TableWithinExpListTask extends AsyncTask {
private final int TABLE_BORDER = 1;
private final int TABLE_TEXT_PADDING = 10;
private Context context = null;
private String str = null;
private boolean tableHeader = false;
private LinearLayout column = null;
public TableWithinExpListTask(Context context, String str, boolean tableHeader, LinearLayout column) {
this.context = context;
this.str = str;
this.tableHeader = tableHeader;
this.column = column;
}
@Override
protected LinearLayout doInBackground(Params... arg0) {
return this.createFormattedCell(this.tableHeader, this.str);
}
@Override
protected void onPostExecute(LinearLayout result) {
this.column.addView(result);
}
private LinearLayout createFormattedCell(boolean tabHeader, String str) {
// Layout che circonda le textView necessario per disegnare il bordo
// delle celle
LinearLayout container = new LinearLayout(this.context);
container.setPadding(TABLE_BORDER, TABLE_BORDER, 0, 0);
container.setBackgroundColor(Color.BLACK);
TextView textView = new TextView(this.context);
textView.setPadding(TABLE_TEXT_PADDING, TABLE_TEXT_PADDING, TABLE_TEXT_PADDING, TABLE_TEXT_PADDING);
textView.setBackgroundColor(Color.WHITE);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
textView.setLayoutParams(params);
if (tabHeader) {
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setBackgroundColor(this.context.getResources().getColor(R.color.light_grayish_orange));
}
textView.setText(str);
container.addView(textView);
return container;
}
}
我看到这个其他的问题,但我不完全理解在这种情况下这种行为。