Android 如何在同一活动类的ocreate()方法中添加的其他方法中更改框架布局背景和文本?

Android 如何在同一活动类的ocreate()方法中添加的其他方法中更改框架布局背景和文本?,android,Android,/**如何更改其他方法onclick listener中的框架布局背景和文本,我们在同一活动类的ocreate()方法中添加了该方法*/ public class MainActivity extends Acitvity{ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);

/**如何更改其他方法onclick listener中的框架布局背景和文本,我们在同一活动类的ocreate()方法中添加了该方法*/

 public class MainActivity extends Acitvity{ 

               public void onCreate(Bundle savedInstanceState){    
                     super.onCreate(savedInstanceState);    
                     setContentView(R.layout.mainView);     **//Main view**  
                     final FrameLayout rootLayout = (FrameLayout)findViewById    (R.id.mainViewRootLayout);    
                     FrameLayout ribbonLayout = (FrameLayout)findViewById(R.id.mainribbonLayout);    
                     TextView ribbonText = (TextView)findViewById(R.id.mainribbonLayoutText);    
                     ribbonText.setText("MainRibbonViewBeforeClick");  

                     LayoutInflater inflater = (LayoutInflater)getSystemService     (context.Layout_Inflater_service);   

                    addRow(rootLayout);  
             }  
            }

    /*Here is the calling method in same class which adds one more text view, if we click on text view the ribbon text of oncreate method has to be changed*/ 


      public void addRow(FrameLayout rootLayout)
           {
          Rect rect = new Rect();
          rootLayout.getDrawingRect(rect);
          FrameLayout ribbonLayout = (FrameLayout)findViewById(R.id.subRibbonLayout);
          TextView subText = (TextView)findViewById(R.id.subribbonLayoutText);
          subText.setText("ClicktoChangeTheRibbon");
          subText.setOnclickListener(new onClickListener()  **//Setting up the listener 
         {   
         public vid onclick(View v){     
          FrameLayout ribbonLayout = (FrameLayout)findViewById(R.id.mainribbonLayout);   

                     TextView ribbonText = (TextView)findViewById(R.id.mainribbonLayoutText);    
                     ribbonText.setText("SubRibbonAfterClick");  


                  /*Here I need to implement a code that changes the ribbon text which I have added in onCreate method*/  
                     }  
                });  
您应该创建

FrameLayout ribbonLayout 
TextView ribbonText 
在public void onCreate(Bundle savedInstanceState)行上方。 它将为整个活动创建可变生存期。因此,在任何活动中,您都可以访问它


当前,您创建的对象仅可用于onCreate方法。

感谢SharpDeveloper,这也可以使用。。我又发了一个问题,事实上我需要尽快更正。。你能看一下吗?