用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

UI框架

2018-05-25 作者: 云代码会员举报

[android]代码库

package com.example.demo7_frag;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends FragmentActivity {

    public final static int num = 3 ; 
    
    Fragment homeFragment;
    Fragment personFragment;
    Fragment sorttypeFragment;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;
    private RadioGroup radioGroup;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		fragmentManager = getSupportFragmentManager();
//        radioGroup = (RadioGroup)findViewById(R.id.radioGroup1);
//        ((RadioButton)radioGroup.findViewById(R.id.radio0)).setChecked(true);
        
        transaction = fragmentManager.beginTransaction();
        Fragment fragment = new HomeFragment();
        transaction.replace(R.id.content, fragment);
        transaction.commit();
       
//        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup group, int checkedId) {
//            	switch (checkedId) {
//				case R.id.radio0:
//					transaction = fragmentManager.beginTransaction();
//	                Fragment homeFragment = new HomeFragment();
//	                transaction.replace(R.id.content, homeFragment);
//	                transaction.commit();
//					break;
//				case R.id.radio1:
//					transaction = fragmentManager.beginTransaction();
//	                Fragment sortFragment = new SortFragment();
//	                transaction.replace(R.id.content, sortFragment);
//	                transaction.commit();
//					break;
//				case R.id.radio2:
//					transaction = fragmentManager.beginTransaction();
//	                Fragment personFragment = new PersonFragment();
//	                transaction.replace(R.id.content, personFragment);
//	                transaction.commit();
//					break;
//            	}
//                
//            }
//        });
	}
	
        public void clickSele(View target){
    		switch (target.getId()) {
    		case R.id.Layout1:
    			transaction = fragmentManager.beginTransaction();
                Fragment homeFragment = new HomeFragment();
                transaction.replace(R.id.content, homeFragment);
                transaction.commit();
				break;
				
    		case R.id.Layout2:
    			transaction = fragmentManager.beginTransaction();
                Fragment sortFragment = new SortFragment();
                transaction.replace(R.id.content, sortFragment);
                transaction.commit();
    			break;
    			
    		case R.id.Layout3:
    			transaction = fragmentManager.beginTransaction();
                Fragment personFragment = new PersonFragment();
                transaction.replace(R.id.content, personFragment);
                transaction.commit();
                break;

        	
    		
    	}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

[源代码打包下载]




网友评论    (发表评论)

共2 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...