gpt4 book ai didi

java - LayoutInflater wordSpan

转载 作者:行者123 更新时间:2023-11-29 03:24:06 25 4
gpt4 key购买 nike

我想在 OnCreateView 中设置 wordtoSpan 字符串。

我的代码:

package com.tachles;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Spannable;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class History_moadim_a extends Fragment {

TextView horef;
TextView kaiz;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.history_moadim_a, container, false);

return rootView;

horef = (TextView) findViewById(R.id.textView3);
Spannable wordtoSpan = new SpannableString("hgh");
horef.setText(wordtoSpan);



}
}

Eclipse 说我不能使用 findViewById,所以我尝试插入 getView() 但仍然是同样的问题。请告诉我我的错误

谢谢

最佳答案

如果 history_moadim_a 是包含 textView3 的布局,请将 onCreateView() 更改为类似

View rootView = inflater.inflate(R.layout.history_moadim_a, container, false);

horef = (TextView) rootView.findViewById(R.id.textView3);
Spannable wordtoSpan = new SpannableString("hgh");
horef.setText(wordtoSpan);

return rootView;

您想在刚刚扩充的布局 (rootView) 中找到 TextView,并在末尾 返回布局(而不是在方法的中间)。

关于java - LayoutInflater wordSpan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21984226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com