-1
//This is the TextViewExample class
public class TextViewExample {
private TextView mTextViewExample;
public TextViewExample(Activity activity) {
mActivity = activity;
mTextViewExample = (TextView)mActivity.findViewById(R.id.TextViewLayout);
}
}
//This is the Fragment class
public class TextViewFragment extends Fragment {
private TextViewExample mText;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mText = new TextViewExample(getActivity());
}
}
mText
未在UI中更新!有人可以解釋正確顯示TextView
從調用片段中的活動的正確方法。android - TextView不會在UI中更新
感謝=)
可以直接通過'findViewById'訪問'TextView'在'onCrateView',你爲什麼用'TextViewExample'? –
您是否在作爲參數傳遞給您的課程的活動中調用了setContentView(..)? – user1841702
你還沒有誇大任何&如果你想創建一個動態的TextView,那麼你需要將其添加到您的佈局。我沒有看到任何特定的Android標準..請學習android&fragment的基本知識.. !! –