80,427
社区成员
发帖
与我相关
我的任务
分享
package com.test.layout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;
import android.text.Editable;
public class TestlayoutActivity extends Activity {
Button okButton;
Button cancelButton;
OnClickListener btnClick;
EditText inputtext;
public native String getresult(Editable input);//声明native方法,用于提取用户输入并传到C中
//并从C中接受返回值,并使用Toast输出
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
okButton=(Button)findViewById(R.id.OK);
cancelButton=(Button)findViewById(R.id.Cancel);
inputtext=(EditText)findViewById(R.id.Input);
btnClick = new OnClickListener() {
@Override
public void onClick(View v){
if (v == okButton) {
Editable input = inputtext.getText();
String output = getresult(input);
Toast.makeText(TestlayoutActivity.this,output, Toast.LENGTH_SHORT).show();
} else if (v == cancelButton) {
inputtext.getText().clear();
}
}
};
okButton.setOnClickListener(btnClick);
cancelButton.setOnClickListener(btnClick);
}
static {
System.loadLibrary("inputtest");
}
}