我在一个片段中有一个TableLayout,一旦通过以下代码创建了片段,我就会生成行(为了测试而简化):
public void displayChar(String ClassID) {
Character charac = new Character(Integer.parseInt(ClassID), getActivity());
TableLayout stanceListTable = (TableLayout) getView().findViewById(R.id.charStanceList);
stanceListTable.removeAllViews();
i=0;
for (Character.StanceCondition stanceCondition : stanceList) {
TableRow row=createTableRow(stanceCondition);
((TextView)row.findViewById(R.id.stances)).setText(Integer.toString(i));
Log.i("RowContent",((TextView)row.findViewById(R.id.stances)).getText().toString());
stanceListTable.addView(row);
i++;
}
}
在我的活动(仅包含此片段)的第一次创建时
我有很好的输出:
但旋转后:
但最糟糕的是日志是正确的!
之前
08-02 12:30:37.446 5697-5697/com.lectem.gecharacters I/RowContentï¹ 0
08-02 12:30:37.449 5697-5697/com.lectem.gecharacters I/RowContentï¹ 1
08-02 12:30:37.466 5697-5697/com.lectem.gecharacters I/RowContentï¹ 2
08-02 12:30:37.469 5697-5697/com.lectem.gecharacters I/RowContentï¹ 3
之后
08-02 12:30:45.653 5697-5697/com.lectem.gecharacters I/RowContentï¹ 0
08-02 12:30:45.656 5697-5697/com.lectem.gecharacters I/RowContentï¹ 1
08-02 12:30:45.660 5697-5697/com.lectem.gecharacters I/RowContentï¹ 2
08-02 12:30:45.662 5697-5697/com.lectem.gecharacters I/RowContentï¹ 3
createTableRow方法:
public TableRow createTableRow(Character.StanceCondition stanceCondition) {
TableRow row =(TableRow) ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.stance_list_row,null);
TextView hands=(TextView)row.findViewById(R.id.stanceHands);
hands.setText(stanceCondition.RHand + stanceCondition.LHand);
TextView stancesView =(TextView)row.findViewById(R.id.stances);
MovementMethod movementMethod = stancesView.getMovementMethod();
if ((movementMethod == null) || !(movementMethod instanceof LinkMovementMethod))
{
stancesView.setMovementMethod(LinkMovementMethod.getInstance());
}
Log.i("row","creating row");
SpannableString finalss=new SpannableString("");
stancesView.setText(finalss);
return row;
}
为什么它会显示错误的文本而getText方法返回正确的内容。。。第一个TextView具有良好的文本。
这真的让我发疯了,问题是什么?
编辑:
这是我的活动的onCreate函数:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_char_details);
ClassID = getIntent().getExtras().getString("ClassID");
mDetailsFragment = (CharDetailsFragment) getSupportFragmentManager().findFragmentById(
R.id.charDetails);
mDetailsFragment.displayChar(ClassID);
}
对于我的片段:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_char_details, container, false);
}
编辑2:
问题似乎来自
MovementMethod movementMethod = stancesView.getMovementMethod();
if ((movementMethod == null) || !(movementMethod instanceof LinkMovementMethod))
{
stancesView.setMovementMethod(LinkMovementMethod.getInstance());
}
你知道我该怎么修吗?