题目
编写Android程序对各种查找与排序算法进行测试
提交运行结果截图
推送代码到码云
解答
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity{
EditText editText;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.text);
Button button1 = (Button) findViewById(R.id.search);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = editText.getText().toString();
Intent intent = new Intent(MainActivity.this, Search.class);
intent.putExtra("extra_data", data);
startActivity(intent);
}
});
Button button2 = (Button)findViewById(R.id.sort);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = editText.getText().toString();
Intent intent = new Intent(MainActivity.this, Search.class);
intent.putExtra("extra_data", data);
startActivity(intent);
}
});
}
}