chenxia223602 2015-01-09 15:00 采纳率: 0%
浏览 1670

两个Activity之间Intent跳转问题

public class Sports extends TabActivity implements OnTabChangeListener{

private TabHost myTabhost;
protected int myMenuSettingTag=0;
private ListView listView,listView2;
private String strArr[] = {"野外登山","高山蹦极","徒步远足","海滩沐浴"};
private Button button1 = null;
private CheckBox checkBox1,checkBox2,checkBox3,checkBox4,checkBox5,checkBox6;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);




    checkBox1=(CheckBox)findViewById(R.id.checkBox1);
    checkBox2=(CheckBox)findViewById(R.id.checkBox2);
    checkBox3=(CheckBox)findViewById(R.id.checkBox3);
    checkBox4=(CheckBox)findViewById(R.id.checkBox4);
    checkBox5=(CheckBox)findViewById(R.id.checkBox5);
    checkBox6=(CheckBox)findViewById(R.id.checkBox6);




    myTabhost=this.getTabHost();
    LayoutInflater.from(this).inflate(R.layout.sports, myTabhost.getTabContentView(), true);
    myTabhost.setBackgroundResource(R.drawable.backgroud3);

    myTabhost
    .addTab(myTabhost.newTabSpec("One")
            .setIndicator("球类运动",
                    getResources().getDrawable(R.drawable.tab1))
            .setContent(R.id.tab1));




   myTabhost
    .addTab(myTabhost.newTabSpec("Two")
            .setIndicator("水上项目",
                    getResources().getDrawable(R.drawable.tab2))
            .setContent(R.id.tab2));


  myTabhost
    .addTab(myTabhost.newTabSpec("Three")
            .setIndicator("野外项目",
                    getResources().getDrawable(R.drawable.tab3))
            .setContent(R.id.tab3));

    listView=(ListView)findViewById(R.id.listView);
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
        this, 
        android.R.layout.simple_list_item_1, 
        strArr);

    listView.setAdapter(arrayAdapter);


    myTabhost
    .addTab(myTabhost.newTabSpec("Four")
            .setIndicator("专业健身",
                    getResources().getDrawable(R.drawable.tab4))
            .setContent(R.id.tab4));

    listView2=(ListView)findViewById(R.id.listView2);
    SimpleAdapter adapter = new SimpleAdapter(this,getList(),
            R.layout.vlist,
            new String[]{"title","img"},
            new int[]{R.id.title,R.id.img});

        listView2.setAdapter(adapter);

    myTabhost.setOnTabChangedListener(this);



    myTabhost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            // TODO Auto-generated method stub
        }
    });

}



private ArrayList<HashMap<String, Object>> getList() 
{
    ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("title", "器械运动(拉力器、俯卧撑等)");
    map.put("img", R.drawable.sports1);
    list.add(map);

    map = new HashMap<String, Object>();
    map.put("title", "有氧运动(跑步、健美操等)");
    map.put("img", R.drawable.sports2);
    list.add(map);

    map = new HashMap<String, Object>();
    map.put("title", "拉伸运动(瑜伽、普拉提等)");
    map.put("img", R.drawable.sports3);
    list.add(map);

    return list;
}




@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub

    if(keyCode==KeyEvent.KEYCODE_BACK){
        Intent intent=new Intent();
        intent.setClass(Sports.this,MainActivity.class);
        startActivity(intent);
        Sports.this.finish();
    }

    return super.onKeyDown(keyCode, event);
}


@Override
public void onTabChanged(String arg0) {
    // TODO Auto-generated method stub
    if (arg0.equals("One")) {

            button1.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Dialog dialog=new AlertDialog.Builder(Sports.this)
                    .setTitle("状态")
                    .setMessage("本程序由Easy制作\nVersion 0.01")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                        }
                    }).create();

                    dialog.show();
                }
            });
        }

    if (arg0.equals("Two")) {
        myMenuSettingTag = 2;
    }
    if (arg0.equals("Three")) {
        myMenuSettingTag = 3;
    }
    if (arg0.equals("Four")) {
        myMenuSettingTag = 4;
    }
}

}
这是sports.java

public class SportsCheck extends Activity {
private Button button01 = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sports);
button01=(Button)findViewById(R.id.button1);
button01.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent=new Intent();
            intent.setClass(SportsCheck.this,SportsCheck1.class);
            startActivity(intent);
           SportsCheck.this.finish();
        }
    });


}

public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub

    if(keyCode==KeyEvent.KEYCODE_BACK){
        Intent intent=new Intent();
        intent.setClass(SportsCheck.this,SportsCheck1.class);
        startActivity(intent);
        SportsCheck.this.finish();
    }

    return super.onKeyDown(keyCode, event);
}

}
这是Sportscheck.Java

public class SportsCheck1 extends Activity {

private Button button1=null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sportscheck1);

    button1=(Button)findViewById(R.id.back);
    button1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent=new Intent();
            intent.setClass(SportsCheck1.this,SportsCheck.class);
            startActivity(intent);
           SportsCheck1.this.finish();
        }
    });

}



@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub

    if(keyCode==KeyEvent.KEYCODE_BACK){
        Intent intent=new Intent();
        intent.setClass(SportsCheck1.this,SportsCheck.class);
        startActivity(intent);
        SportsCheck1.this.finish();
    }

    return super.onKeyDown(keyCode, event);
}

}

这是sportscheck1.java


  • 写回答

2条回答 默认 最新

  • danielinbiti 2015-01-09 16:35
    关注

    想要干嘛?要解决什么问题

    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划