紫易语风 2016-04-20 04:43 采纳率: 0%
浏览 1225

java AS新手求助。以下是代码:

setOnCheckedChangeListener方法参数类型不匹配

ackage gke_code_jrxd.Demo.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import gke_code_jrxd.Demo.BuildConfig;
import gke_code_jrxd.Demo.R;
import gke_code_jrxd.Demo.ui.index.FunnyFragment;
import gke_code_jrxd.Demo.ui.index.IndexFragment;
import gke_code_jrxd.Demo.ui.index.NewsFragment;
import gke_code_jrxd.Demo.ui.widget.TitleBar;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends FragmentActivity {

@Bind(R.id.titleBar)
TitleBar titleBar;

@Bind(R.id.rgTabBar)
RadioButton rgTabBar;

@Bind(R.id.rbTabIndex)
RadioButton rbTabIndex;

@Bind(R.id.rbTabNews)
RadioButton rbTabNews;

@Bind(R.id.rbTabFunny)
RadioButton rbTabFunny;

IndexFragment mIndexFragment = new IndexFragment();
NewsFragment mNewsFragment = new NewsFragment();
FunnyFragment mFunnyFragment = new FunnyFragment();

@Override
protected void onCreate(Bundle savedInstanceState) {

// this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去除标题栏

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    titleBar.setTitle("首页");
    titleBar.setLeftTextLeftDrawable("", 0);
    addFragment();

rgTabBar.setOnCheckedChangeListener(mOnCheckedChangeListener);

    // rgTabBar.check(R.id.rbTabIndex);
    // 在这里为什么不用 check(R.id.rbTabIndex)默认选中第一项,是因为y
    // mOnCheckedChangeListener事件会执行多次,所以弃用它,
    // 直接让第一个RadioButton设置选中解决该问题
    rbTabIndex.setChecked(true);
}

/**
 * 首页tab索引
 **/
final int TAB_INDEX = 0;
/**
 * 今日新闻tab索引
 **/
final int TAB_NEWS = 1;
/**
 * 今日笑点tab索引
 **/
final int TAB_FUNNY = 2;
/**
 * 当前展示的tab索引
 **/
int mCurShowFragmentIndex;
/**
 * tab选项卡监听器
 */
RadioGroup.OnCheckedChangeListener mOnCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {

    @Override
    public void OnCheckedChanged(RadioGroup group,int checkedId) {
        switch (checkedId) {
            case R.id.rbTabIndex:
                changeTab(TAB_INDEX);
                break;
            case R.id.rbTabNews:
                changeTab(TAB_NEWS);
                break;
            case R.id.rbTabFunny:
                changeTab(TAB_FUNNY);
                break;
        }
    }
};
public void addFragment() {
    FragmentTransaction transaction = getSupportFragmentManager()
            .beginTransaction();
    transaction.add(R.id.flContent, mIndexFragment);
    transaction.add(R.id.flContent, mNewsFragment);
    transaction.add(R.id.flContent, mFunnyFragment);
    transaction.commit();

    showFragment(TAB_INDEX);
}

/**
 * 切换 tab选项卡
 * @param tabItem
 */
public void changeTab(final int tabItem) {
    switch (tabItem) {
        case TAB_INDEX:
            titleBar.setTitle("首页");
            mCurShowFragmentIndex = TAB_INDEX;
            showFragment(TAB_INDEX);
            break;
        case TAB_NEWS:
            titleBar.setTitle("今日新闻");
            mCurShowFragmentIndex = TAB_NEWS;
            showFragment(TAB_NEWS);
            break;
        case TAB_FUNNY:
            titleBar.setTitle("今日笑点");
            mCurShowFragmentIndex = TAB_FUNNY;
            showFragment(TAB_FUNNY);
            break;
    }
    //showFragment(mCurShowFragmentIndex);
}
/**
 * hide所有的fragment
 */
private void hideFragment() {
    FragmentTransaction transaction = getSupportFragmentManager()
            .beginTransaction();
    transaction.hide(mIndexFragment);
    transaction.hide(mNewsFragment);
    transaction.hide(mFunnyFragment);
    transaction.commit();
}
/**
 * show选中的fragment
 *
 * @param tab
 */
public void showFragment(final int tab) {
    hideFragment();
    FragmentTransaction transaction = getSupportFragmentManager()
           .beginTransaction();
    switch (tab) {
        case TAB_INDEX:
            transaction.show(mIndexFragment);
            break;
        case TAB_NEWS:
            transaction.show(mNewsFragment);
            break;
        case TAB_FUNNY:
            transaction.show(mFunnyFragment);
            break;
    }
    transaction.commit();
}

}

  • 写回答

1条回答 默认 最新

  • qq_34688538 2016-04-20 04:56
    关注
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境