我已经根据现有 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 {}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)