我正在尝试添加和修改另一个布局内的布局中的一些文本。
我正在尝试通过调用下一个方法来执行此操作,但在尝试修改tv_event_hour
的文本时崩溃了。
行:tv_event_hour.setText(getHour(timestamp) + " - ");
有什么问题?
public void addInputDescription(int timestamp, String description)
{
LinearLayout mRootLayout = (LinearLayout) findViewById(R.id.event_container);
LayoutInflater inflater = (LayoutInflater) _c.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View mChildView = inflater.inflate(R.layout.program_event_day_header, mRootLayout, false);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mRootLayout.addView(mChildView, params);
TextView tv_event_hour = (TextView) mChildView.findViewById(R.id.tv_event_hour);
TextView tv_event_message = (TextView) mChildView.findViewById(R.id.tv_event_message);
tv_event_hour.setText(getHour(timestamp) + " - ");
tv_event_message.setText(description);
}
public String getHour(long timeStamp){
Date df = new Date(timeStamp*1000);
return new SimpleDateFormat("HH:mm").format(df);
}