我试图从文件 Duality.java 中获取一个方法,以便在单击按钮时在 Min.Java 中运行。以下是这两个文件以及我目前正在尝试做的事情,这是行不通的。在 Min.java 中单击按钮时,如何让方法 duality() 运行?
对偶性.java
package com.android.control;
import android.util.Log;
import com.map.AppName.R;
public class duality {
public void duality(){
Log.e("Did It Run","Yes it ran");
}
}
最小java
package com.android.control;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.map.AppName.R;
public class Min extends LinearLayout {
Button but;
private final int ELEMENT_HEIGHT = 60;
private final int ELEMENT_WIDTH = 80;;
private final int TEXT_SIZE = 30;
public Min( Context context, AttributeSet attributeSet ) {
super(context, attributeSet);
this.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ) );
LayoutParams elementParams = new LinearLayout.LayoutParams( ELEMENT_WIDTH, ELEMENT_HEIGHT );
createBut( context );
addView( but, elementParams );
}
private void createButton( Context context){
but = new Button( context );
but.setTextSize( TEXT_SIZE );
but.setText( "Go" );
but.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Duality duality = new duality();
}
});
}
}