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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?