80,351
社区成员
发帖
与我相关
我的任务
分享
public class MainActivity extends Activity {
ActionBar.Tab tab1, tab2, tab3;
Fragment fragmentTab1 = new Tab_Conf();
Fragment fragmentTab2 = new Tab_Results();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
tab1 = actionBar.newTab().setText("1");
tab2 = actionBar.newTab().setText("2");
tab3 = actionBar.newTab().setText("3");
tab1.setTabListener(new MyTabListener(fragmentTab1));
tab2.setTabListener(new MyTabListener(fragmentTab2));
tab3.setTabListener(new MyTabListener(fragmentTab3));
actionBar.addTab(tab1);
actionBar.addTab(tab2);
actionBar.addTab(tab3);
}
}
public class MyTabListener implements ActionBar.TabListener {
Fragment fragment;
public MyTabListener(Fragment fragment) {
this.fragment = fragment;
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// nothing done here
}
}
public class Tab_Conf extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
View view = inflater.inflate(R.layout.tab_conf, container, false);
EditText txt_long;
txt_long = (EditText) view.findViewById(R.id.txt_longitude);
EditText txt_lati;
txt_lati = (EditText) view.findViewById(R.id.txt_latitude);
EditText txt_radius;
txt_radius = (EditText) view.findViewById(R.id.txt_radius);
txt_long.setText("45");
txt_lati.setText("-79");
txt_radius.setText("100");
return view;
}
}
public class Tab_Results extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_results, container, false);
EditText txt_long = (EditText) getActivity().findViewById(R.id.txt_longitude);
String long_str = txt_long.getText().toString();
}
}