androidannotations @AfterViews 没有调用并且 editText 为空 [英] androidannotations @AfterViews is not calling and editText is null
本文介绍了androidannotations @AfterViews 没有调用并且 editText 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类,它从 Fragment 扩展而来.在一个类中,我的 editText 为空,@AfterViews 没有调用这里是我的代码:
I have a class and it extends from Fragment. Inside a class my editText is null and @AfterViews is not calling here is my code:
@EFragment
public class Search extends Fragment {
private final String TAG = Search.class.getCanonicalName();
private static ProgressDialog progressDialog;
private Activity activity;
private ArrayList<String> urlList = new ArrayList<String>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.search, container, false);
Log.i(TAG, "onCreateView");
return rootView;
}
@ViewById
RadioButton firstRadio;
@ViewById
RadioButton secondRadio;
@ViewById(R.id.editText1)
EditText editText1;
@AfterViews
void afterViews() {
int a = 1;
a++;
Log.i(TAG, editText1 + "AfterViews");
Log.i(TAG, a + "aaaaaaaa");
}
private void extractUrlsFromText(String s) {
Matcher matcher = Patterns.WEB_URL.matcher(s);
while (matcher.find())
urlList.add(matcher.group());
}
public void searchWebUrl() {
Log.i(TAG, editText1 + "searchWebUrl");
String text = editText1.getText().toString();
if (!TextUtils.isEmpty(text))
extractUrlsFromText(text);
parseWithUrls(urlList);
((Main) getActivity()).switchToFragmentUrlList(urlList);
}
}
请帮我解释一下为什么editText是空的,谢谢!
Please help me why editText is null thanks in advance!
推荐答案
你必须让 AndroidAnnotations
处理布局膨胀并注入视图引用:
You have to let AndroidAnnotations
handle the layout inflation and inject the view reference:
@EFragment(R.layout.my_fragment_layout)
public class MyFragment extends Fragment {
@ViewById(R.id.my_text_view) // must exist in layout, must be of correct type
TextView mTextView;
@AfterViews
void initViews() {
mTextView.setText("Hello World");
}
}
然后使用带有 _
前缀的生成类.
An then use the generated class with _
prefix.
这篇关于androidannotations @AfterViews 没有调用并且 editText 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文