一.main中
package com.example.jiekoudiaoyong;
import com.example.jiekoudiaoyong.MyButton.OnCliListener;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity implements OnCliListener{
MyButton ll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ll=new MyButton();
ll.setOnCliListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onResf() {
// TODO Auto-generated method stub
Log.v("aaa", "成功调用");
}
}
二.MyButton类中
package com.example.jiekoudiaoyong;
import android.R.integer;
import android.util.Log;
public class MyButton {
OnCliListener cliListener;
public MyButton()
{
}
public void setOnCliListener(OnCliListener listener)
{
cliListener=listener;
cliListener.onResf();
}
public interface OnCliListener{
void onResf();
}
}