0

我为视图编写了一个单独的类。我需要根据用户需求显示/隐藏一些字段。但是 setvisible(View.GONE) 和 setVisible(View.Invisible) 不起作用。

我已经尝试过使用无效但仍然是相同的结果。

@Override
public View view() {
    LayoutInflater inflater1 = LayoutInflater.from(currentActivity);
    View row = inflater1.inflate(R.layout.personal_form, null);

    ed_name = (EditText) row.findViewById(R.id.ed_name);
    ed_email = (EditText) row.findViewById(R.id.ed_email);
    ed_phone = (EditText) row.findViewById(R.id.ed_phone);
    ed_address = (EditText) row.findViewById(R.id.ed_address);
    ed_zipcode = (EditText) row.findViewById(R.id.ed_zip_code);
    ed_title = (EditText) row.findViewById(R.id.ed_title);
    ed_country = (EditText) row.findViewById(R.id.ed_country);

    ImageView img_name = (ImageView) row.findViewById(R.id.img_name);
    ImageView img_email = (ImageView) row.findViewById(R.id.img_email);
    ImageView img_phone = (ImageView) row.findViewById(R.id.img_phone);
    ImageView img_address = (ImageView) row.findViewById(R.id.img_address);
    ImageView img_zipcode = (ImageView) row.findViewById(R.id.img_zip_code);
    ImageView img_title = (ImageView) row.findViewById(R.id.img_title);
    ImageView img_country = (ImageView) row.findViewById(R.id.img_country);

    RelativeLayout layout_oned = (RelativeLayout) row.findViewById(R.id.relative_one);
    RelativeLayout layout_twod = (RelativeLayout) row.findViewById(R.id.relative_two);
    RelativeLayout layout_threed = (RelativeLayout) row.findViewById(R.id.relative_three);
    RelativeLayout layout_fourd = (RelativeLayout) row.findViewById(R.id.relative_four);
    RelativeLayout layout_fived = (RelativeLayout) row.findViewById(R.id.relative_five);
    RelativeLayout layout_sixd = (RelativeLayout) row.findViewById(R.id.relative_six);
    RelativeLayout layout_sevend = (RelativeLayout) row.findViewById(R.id.relative_seven);
    RelativeLayout layout_eightd = (RelativeLayout) row.findViewById(R.id.relative_eight);

    ImageView header_imag_one = (ImageView) row.findViewById(R.id.icon);
    ImageView header_imag_two = (ImageView) row.findViewById(R.id.image_id);
    ImageView header_imag_three = (ImageView) row.findViewById(R.id.image_id_two);
    TextView header_tv = (TextView) row.findViewById(R.id.title);

    header_imag_one.setImageResource(R.drawable.ic_launcher);
    header_tv.setText("string_one");

    if (bool) {
        header_imag_three.setVisibility(View.VISIBLE);
        header_imag_two.setVisibility(View.GONE);

        ed_name.setVisibility(View.VISIBLE);
        ed_email.setVisibility(View.VISIBLE);
        ed_phone.setVisibility(View.VISIBLE);
        ed_address.setVisibility(View.VISIBLE);
        ed_zipcode.setVisibility(View.VISIBLE);
        ed_title.setVisibility(View.VISIBLE);
        ed_country.setVisibility(View.VISIBLE);

        // ed_name.setText(StaticInfo.personalInfoBean.name);
        // ed_email.setText(StaticInfo.personalInfoBean.email_id);
        // ed_phone.setText(StaticInfo.personalInfoBean.phone);
        // ed_address.setText(StaticInfo.personalInfoBean.address);
        // ed_zipcode.setText(StaticInfo.personalInfoBean.zip_code);
        // ed_title.setText(StaticInfo.personalInfoBean.title);
        // ed_country.setText(StaticInfo.personalInfoBean.country);

        img_name.setVisibility(View.VISIBLE);
        img_email.setVisibility(View.VISIBLE);
        img_phone.setVisibility(View.VISIBLE);
        img_address.setVisibility(View.VISIBLE);
        img_zipcode.setVisibility(View.VISIBLE);
        img_title.setVisibility(View.VISIBLE);
        img_country.setVisibility(View.VISIBLE);

        layout_oned.setVisibility(View.VISIBLE);
        layout_twod.setVisibility(View.VISIBLE);
        layout_threed.setVisibility(View.VISIBLE);
        layout_fourd.setVisibility(View.VISIBLE);
        layout_fived.setVisibility(View.VISIBLE);
        layout_sixd.setVisibility(View.VISIBLE);
        layout_sevend.setVisibility(View.VISIBLE);
        layout_eightd.setVisibility(View.VISIBLE);
    } else {
        header_imag_three.setVisibility(View.GONE);
        header_imag_two.setVisibility(View.VISIBLE);

        ed_name.setVisibility(View.GONE);
        ed_email.setVisibility(View.GONE);
        ed_phone.setVisibility(View.GONE);
        ed_address.setVisibility(View.GONE);
        ed_zipcode.setVisibility(View.GONE);
        ed_title.setVisibility(View.GONE);
        ed_country.setVisibility(View.GONE);

        img_name.setVisibility(View.GONE);
        img_email.setVisibility(View.GONE);
        img_phone.setVisibility(View.GONE);
        img_address.setVisibility(View.GONE);
        img_zipcode.setVisibility(View.GONE);
        img_title.setVisibility(View.GONE);
        img_country.setVisibility(View.GONE);

        layout_oned.setVisibility(View.GONE);
        layout_twod.setVisibility(View.GONE);
        layout_threed.setVisibility(View.GONE);
        layout_fourd.setVisibility(View.GONE);
        layout_fived.setVisibility(View.GONE);
        layout_sixd.setVisibility(View.GONE);
        layout_sevend.setVisibility(View.GONE);
        layout_eightd.setVisibility(View.GONE);
    }
    row.invalidate();
    header_tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (bool) {
                bool = false;
                submit_request();
            } else {
                bool = true;
            }
            view();
        }
    });
    return row;
}
4

1 回答 1

0

尝试yourView.setVisibility(View.INVISIBLE)代替yourView.setVisible(View.Invisible)

于 2013-05-22T18:16:00.133 回答