我正在尝试以编程方式添加xml布局。它在time.setText(timeFormat);
时出错。当我删除此行时,我得到默认文本值TextView
。此外,我已检查timeFormat
不为空。为什么我会收到此错误?
这是我的代码: 在onCreate()中,
new GetContacts().execute();
addPost(timeFormat,message);
addPost()
功能:
public void addPost(String timef,String postmessage){
LayoutInflater i = getLayoutInflater();
View v = i.inflate(R.layout.list_item, null);
TextView time = (TextView)findViewById(R.id.time);
Log.d("TIME HAS COME", timeFormat);
time.setText(timeFormat);
TextView message1 = (TextView)findViewById(R.id.message);
message1.setText(message);
LinearLayout ll = (LinearLayout)findViewById(R.id.feedsLayout);
ll.addView(v);
}