我已经指定了一个类,基于现有 Android 项目中的另一个类。addRow() 方法应该动态地将行添加到表中。在创建新的 TextView 以添加到我的行以及创建该行时,我应该指定“上下文”。当前的方式,尝试“getApplicationContext()”会抛出 NullPointerException。那么我应该从哪里获得上下文呢?
public class DistanceTableView extends ContactListActivity
{
public void addRow(LocationMessage locationMsg){
View messageView = theInflater.inflate(R.layout.homepage, null);
TableLayout table = (TableLayout)messageView.findViewById(R.id.distanceTable);
TextView senderNameTextView = new TextView(getApplicationContext());
senderNameTextView.setText(locationMsg.getSenderName());
TableRow tr = new TableRow(getApplicationContext());
tr.addView(distanceTextView);
table.addView(tr);
rows.addFirst(messageView);
}
}
我的观点正在扩展的课程:
public class ContactListActivity extends MapActivity implements
ConnectionListener {}