Java 更平坦的字跨度
我想在OnCreateView上设置wordtoSpan字符串 我的代码:Java 更平坦的字跨度,java,android,html,Java,Android,Html,我想在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.
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(),但仍然存在相同的问题。请告诉我我的错误
谢谢你使用
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);
horef = (TextView) rootView.findViewById(R.id.textView3);
Spannable wordtoSpan = new SpannableString("hgh");
horef.setText(wordtoSpan);
return rootView;
}
}
我无法在完美位置的onCreateView中看到return语句,因此请执行returnrootview代码>在逻辑末尾的onCreateView内部,通过onCreateView末尾的方式使用
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);
horef = (TextView) rootView.findViewById(R.id.textView3);
Spannable wordtoSpan = new SpannableString("hgh");
horef.setText(wordtoSpan);
return rootView;
}
}
我无法在完美位置的onCreateView中看到return语句,因此请执行returnrootview如果history\u moadim\u 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;
< P> >您想在刚才展开的布局中找到<代码>文本视图< /> >,并在结束时返回布局(而不是在方法的中间).< /p> > p> >代码> SyryYyMaimDimaA/代码>是包含<代码> TeXVIEW3的布局,将<<代码> OnCeCaleVIEW()/<代码>更改为“”
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;
你想在刚才膨胀的布局中找到<代码>文本视图< /> >(结束代码> RooVIEWS/COD>),并在最后返回布局(而不是在方法的中间)。答案更新了,请看一下请看一下答案,希望能对你有所帮助!!答案是更新的,请看一看你没有完全返回视图,以及请像返回根视图;在onCreateView的末尾,请将视图作为returnrootview返回getView()
内部onCreateView()
将不起作用-您还没有将视图返回到框架,它可以使用getView()
返回。现在片段中没有findViewById()
您也没有完全返回视图,请喜欢返回rootView;在onCreateView的末尾,请将视图作为returnrootview返回getView()
内部onCreateView()
将不起作用-您还没有将视图返回到它可以随getView()
返回的框架中。现在片段中没有findViewById()