@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.title = (String) getTitle();
// Getting reference to the DrawerLayout
this.drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
this.drawerList = (ListView) findViewById(R.id.drawer_list);
this.fragments[0] = new My_Main_Fragment(this);
this.fragments[1] = new My_Breakfast_Fragment();
this.fragments[2] = new My_Lunch_Fragment();
this.fragments[3] = new My_Dinner_Fragment();
this.fragments[4] = new My_Dessert_Fragment();
this.fragments[5] = new My_Seat_Plan_Fragment();
this.fragments[6] = new My_Beverages_Fragment();
this.item_titles = getResources().getStringArray(R.array.menu_items);
............................................... .................................................. .................................................. .................................................. ............
public class My_Seat_Plan_Fragment extends Activity{
按钮创建,编辑,查看,删除,查找;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.air_main_interface);
create = (Button)findViewById(R.id.note_add);
edit = (Button)findViewById(R.id.note_edit);
view = (Button)findViewById(R.id.note_view);
delet = (Button)findViewById(R.id.note_delete);
find = (Button)findViewById(R.id.note_find);
create.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent in = new Intent(My_Seat_Plan_Fragment.this,Seat_create.class);
startActivity(in);
}
});
............................................... ................................................. < / p>
在下面附加的两个类中,我需要将主要活动与片段类连接... 主要活动遵循扩展活动实现My_Fragments_Parent {
和片段活动如下所示公共类My_Seat_Plan_Fragment扩展活动{
但我在行
中的主要活动中遇到错误this.fragments [5] = new My_Seat_Plan_Fragment(); ------说无法从我的Seat_Plan_Fragment转换为Fragment
因此,如果我更改我的seat_Plan片段扩展活动,则无法完成按钮活动...
答案 0 :(得分:0)
如果我理解了这个问题,你可以在你的片段中使用这样的东西:
((MainActivity) getActivity()).someMethod();