Checked Box没有变得可见

时间:2015-10-12 11:05:42

标签: android

我是Android应用程序的新用户,我需要帮助,当我点击放置在工具栏中的图标

时,我在Gridview中放置的复选框无法显示

代码: -

var companyServiceMock = new Mock<ICompanyService>();

        companyServiceMock.Setup(x => x.GetCompanyByRegistrationNumber(It.IsAny<string>()))
        .Returns(new Company()
        {
            RegistrationNumber = "12333",
        });

_paymentService = new PaymentService(_companyService, _accountService, _settings, _settingsHelper, _scheduleManagerService, _appSettingService);

2 个答案:

答案 0 :(得分:1)

您还需要刷新适配器:

adapter.notifyDataSetChanged();

答案 1 :(得分:1)

它不会那样,因为CheckBoxGridView中,所以你需要通知适配器。

试试这个:

public class MyActivity extends Fragment {

   boolean mIsCheckBoxVisible;

   public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
     myView=inflater.inflate(R.layout.activity_room_summary,null);
     setHasOptionsMenu(true);
     initializeValue();
     return myView;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if(id == R.id.action_dash){
        mIsCheckBoxVisible = true;
        adapter.notifyDataSetChanged();
        return true;
    }
      return super.onOptionsItemSelected(item);
    }
}

public void initializeValue(){
  adapter = new MyAdapter(ctx, R.layout.activity_list, listMy);
}


public class MyAdapter extends ArrayAdapter<My> {
  @Override
  public View getView ( int position, View convertView, ViewGroup parent ) {

     if(mIsCheckBoxVisible){
       checkBox.setVisibility(View.VISIBLE);
     } else {
       checkBox.setVisibility(View.INVISIBLE);
     }
  }
}