1

让我解释一下,我有这个Activity,那里有 aButton和 a TextView。我必须为此按钮创建一个侦听器(不能是内部类或私有类),让我们调用ButtonListener. 我需要TextViewActivity内部更改ButtonListener. 我怎么做?

活动 -->Button b, TextView t

b.setOnClickListener(ButtonListener listener)

listener --> onClick(){ //这里需要改变TextView }

谢谢

4

1 回答 1

1
public class YourActivity extends Activity {

ImageView    button     = null;
TextView     text       = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.yourlayoutxml);

    text       = (TextView)  findViewById(R.id.id_TextView);
    button     = (ImageView) findViewById(R.id.id_ImageView);


    button.setOnClickListener(new OnClickListener() 
    {
            @Override
            public void onClick(View v) 
            {
                    //here you can manage your TextView     
                    text.doSomething();
            }
      }                         );
}
}

希望这有帮助。

于 2012-05-30T13:21:18.540 回答