更新片段中的textView

时间:2013-02-18 13:38:50

标签: android android-layout android-fragments textview

当我尝试在对话片段后更新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();    
                }
            }

overlapping label

0 个答案:

没有答案