0

我在当前活动的 viewpager 中为布局充气,但我需要设置此布局的 textview 文本,以便我可以充气它并显示我正在做的新文本:

LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.mylayout, null);
TextView txt=(TextView)findViewById(R.id.content);
txt.setText(cursor.getString(cursor.getColumnIndex("Content")));

但这给了我一个空指针异常,我该如何解决这个问题如何设置我不在的布局的 textview 的文本,这意味着来自该布局之外..

4

2 回答 2

2

改变 -TextView txt=(TextView)findViewById(R.id.content);

TextView txt=(TextView)view.findViewById(R.id.content);

于 2013-09-10T12:10:46.620 回答
1

要找到您想要的 textView,您必须指定 parentView 等

TextView txt=(TextView)view.findViewById(R.id.content);
于 2017-04-18T23:49:27.867 回答