Guest User

Untitled

a guest
Jan 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. package com.example.phi.myapplication6;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.widget.TextView;
  6. import android.widget.Button;
  7. import android.util.Log;
  8. import android.view.View;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12. // Used to load the 'native-lib' library on application startup.
  13. static {
  14. System.loadLibrary("native-lib");
  15. }
  16. private TextView tv;
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_main);
  22.  
  23. // Example of a call to a native method
  24. tv = (TextView) this.findViewById(R.id.sample_text);
  25. tv.setText(stringFromJNI());
  26.  
  27.  
  28. // Lấy ra button theo ID
  29. Button button1 = (Button) this.findViewById(R.id.button1);
  30. // Sét đặt sự kiện Click vào Button1.
  31. button1.setOnClickListener(new Button.OnClickListener() {
  32.  
  33. @Override
  34. public void onClick(View view) {
  35.  
  36. tv.setText("Result: " + getStringRandom());
  37. }
  38. });
  39. }
  40.  
  41. /**
  42. * A native method that is implemented by the 'native-lib' native library,
  43. * which is packaged with this application.
  44. */
  45. public native String stringFromJNI();
  46. public native String getStringRandom();
  47.  
  48. }
Add Comment
Please, Sign In to add comment