android开发:这里为什么出错? 点击按钮就出错了,
点击按钮就自动添加一个EditText的功能,但是为什么会出错?请高手看下,谢谢publicstaticclassPlaceholderFragmentextendsFr...
点击按钮就自动添加一个EditText的功能,但是为什么会出错? 请高手看下,谢谢
public static class PlaceholderFragment extends Fragment {
private Button bt;
private LinearLayout li;
private int count=0;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
bt=(Button) rootView.findViewById(R.id.bt);
li=(LinearLayout) rootView.findViewById(R.id.li);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EditText editText=new EditText(getActivity());
editText.setHint("请输入第"+count+"个联系人信息!");
li.addView(editText);
getActivity().setContentView(li);
}
});
return rootView;
} 展开
public static class PlaceholderFragment extends Fragment {
private Button bt;
private LinearLayout li;
private int count=0;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
bt=(Button) rootView.findViewById(R.id.bt);
li=(LinearLayout) rootView.findViewById(R.id.li);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EditText editText=new EditText(getActivity());
editText.setHint("请输入第"+count+"个联系人信息!");
li.addView(editText);
getActivity().setContentView(li);
}
});
return rootView;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询