如何响应在fragment
1个回答
2015-08-10
展开全部
public static class PlaceholderFragment extends Fragment {
TextView textView = null; //创建TextView对象
Button button = null; //创建Button对象
int count = 0; //创建计数器count
public PlaceholderFragment() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//rootView为fragment_main中所有控件集合
View rootView = inflater.inflate(R.layout.fragment_main, container,false);
//获取TextView控件
textView = (TextView)rootView.findViewById(R.id.textView);
//获取Button控件
button = (Button) rootView.findViewById(R.id.button);
//Button按钮的OnClick方法
button.setOnClickListener(new ButtonListener());
return rootView;
}
//创建监听器
class ButtonListener implements OnClickListener{
public void onClick(View v){
count++;
textView.setText(count+"");
}
}
}
TextView textView = null; //创建TextView对象
Button button = null; //创建Button对象
int count = 0; //创建计数器count
public PlaceholderFragment() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//rootView为fragment_main中所有控件集合
View rootView = inflater.inflate(R.layout.fragment_main, container,false);
//获取TextView控件
textView = (TextView)rootView.findViewById(R.id.textView);
//获取Button控件
button = (Button) rootView.findViewById(R.id.button);
//Button按钮的OnClick方法
button.setOnClickListener(new ButtonListener());
return rootView;
}
//创建监听器
class ButtonListener implements OnClickListener{
public void onClick(View v){
count++;
textView.setText(count+"");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询