我的问题是:为什么,如果我使用 LinearLayout,而不是Object
,作为我的AsyncTask
( TableWithinExpListTask<Params, Progress, LinearLayout>
) 的“结果”,Eclipse 会给我很多错误,例如无法实例化 LinearLayout 类型?
在我看来,它不再识别LinearLayout
了,createFormattedCell()
我不明白为什么。
在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<Params, Progress, LinearLayout> extends AsyncTask<Params, Progress, LinearLayout> {
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;
}
}
我看到了关于这个的其他问题,但在这种情况下我并不完全理解这种行为。