0

当我尝试在 dialogfragment 之后更新 Textview 的值时,我得到了正确的值,但如果之前的值更长,它的旧视图在背景中仍然可见(并且丑陋)。

我尝试为当前片段调用onResume()但没有改进。

我只是调用一个对话框,当调用监听器 onFinishEditDialog()时,我只是设置文本

如果我打开另一个应用程序并且我回来了它是完美的(旧的已经消失了)这怎么可能?

在xml布局中:

 <TextView
                    android:id="@+id/txttotalcho"
                    style="@style/importantTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="40dp"
                    android:text="33 cho"
                    android:textSize="64dp" />

在 MainActivity 中:

@Override
    public void onGoToPage(int pageNumber,boolean verso, Pasto p,ArrayList<CiboSelezionato> cibiSelezionati,String extra) {
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            Fragment firstDetail = 

(Fragment)fm.findFragmentByTag(SECOND_DETAIL_FRAGMENT_TAG);
                ft.remove(firstDetail);

                ft.commit();
                        FragmentTransaction ft2 = fm.beginTransaction();
        switch (pageNumber){

                        case Constants.P_SCELTA_PASTO:{
                             WizardPasti10 secondDetail = WizardPasti10.getInstance(this);
        ft2.replace(R.id.anchor_layout,secondDetail,SECOND_DETAIL_FRAGMENT_TAG);
                            break;
                        }
                        case Constants.P_TOTAL_CHO:{
                             WizardPastiTotalCho secondDetail = WizardPastiTotalCho.getInstance(this);
     ft2.replace(R.id.anchor_layout,secondDetail,SECOND_DETAIL_FRAGMENT_TAG);

                            break;
                        }
             ft2.commit();
                    View v1,v2;
                    v1=(View)findViewById(R.id.anchor_left);
                    v2=(View)findViewById(R.id.anchor_layout);
                    v1.setVisibility(View.GONE);
                    v2.setVisibility(View.VISIBLE);
                v2.setBackgroundColor(getResources().getColor(R.color.white));
    }

在片段 WizardPastiTotalCho 中:

private TextView txtTotalCho;
  @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

          View firstView = inflater.inflate(R.layout.wizardpastitotalcho, container, false);
                txtTotalCho = (TextView)firstView.findViewById(R.id.txttotalcho);
            txtTotalCho.setOnClickListener(new OnClickListener(){
                @Override
                public void onClick(View button) {
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
                    DialogFragment newFragment = new TastierinoDialogFragment(WizardPastiTotalCho.this,Constants.CARBOIDRATI,0);
                    newFragment.show(ft, "totalchoDialog");
                }
            });
    }



     @Override
            public void onFinishEditDialog(int dialogType, String inputText) {
     //called when i close the dialogFragment
                txtTotalCho.setText(inputText+" cho");
txtTotalCho.setBackgroundColor(Color.YELLOW);//just to see the difference
                try {
                    totalCho=Float.parseFloat(inputText);
                    tmpPasto.setCarboidrati(totalCho);
                } catch (NumberFormatException e) {
                    e.printStackTrace();    
                }
            }

重叠标签

4

0 回答 0