8 thg 9, 2011

Bubble Sort

BubbleSort
package com.exercise.AndroidBubbleSort;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidBubbleSortActivity extends Activity {
 
 TextView src, result;
 int[] data = new int[10];
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        src = (TextView)findViewById(R.id.src);
        result = (TextView)findViewById(R.id.result);
        
        Random random = new Random();
        String stringSrc = "Src = ";
        for (int i = 0; i < data.length; i++){
         data[i] = random.nextInt(100);
         stringSrc += data[i] + " ";
        }
        
        src.setText(stringSrc);
        
        bubblesort();
        
        String stringResult = "Result = ";
        for (int i = 0; i < data.length; i++){
         stringResult += data[i] + " ";
        }
        
        result.setText(stringResult);
        
    }
    
    void bubblesort() {
     int min;

     for (int i = 0; i < data.length - 1; i++){
      min = i;
      for (int  j = i + 1; j < data.length; j++){
       if (data[j] < data[min]){
        min = j;
       }
      }
      if (i != min){ 
       int tmp = data[i];
       data[i] = data[min];
       data[min] = tmp;
       }
     }
    }

}
 
Nguồn : Android-er.

Trở lại

Bắt đầu trở lại vs blog này. Trở lại với niềm đam mê nào. :D

10 thg 6, 2011

Mùa Tôm

Đêm khuya lặng lẽ
Mưa rơi khe khẽ
Tay cầm chuột...
Ta vẽ ...
Những đường kẽ ...
.........Xong hình cần vẽ
Bỗng ...
Chấm sáng... đốm sáng...
Nghĩ đến ma...
sờ sợ. tắt máy đi ngủ. hết ngày cũ....

24 thg 5, 2011

Source Code Game Sudoku Android

Đây là toàn bộ source code game Sudoku. Các bạn download về kham khảo vào phát triển thêm.
Link download : Tại Đây

19 thg 5, 2011

Tao Alert Dialog with OK and Cancel options Trong Android



Alert Dialog with OK and Cancel options

 AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(AndroidAlertDialog.this);
 myAlertDialog.setTitle("--- Title ---");
 myAlertDialog.setMessage("Alert Dialog Message");
 myAlertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

  public void onClick(DialogInterface arg0, int arg1) {
  // do something when the OK button is clicked
  }});
 myAlertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
       
  public void onClick(DialogInterface arg0, int arg1) {
  // do something when the Cancel button is clicked
  }});
 myAlertDialog.show();
(Suu tam). 

Doc Doan Text trong EditText

Khi ban nhap vao button Play Random Tetx . Chuong trinh se doc doan van ban cua ban voi ngon ngu ma ban chon san. O day minh chon ngon ngu la English.
Do dung ubuntu chua co unikey nen viet khong dau. Mong cac ban thong cam.
Hinh cua chuong trinh :

Bản beta đầu tiên

Sau 6 tháng cả team cặm cụi làm việc điên cuồng, bản alpha cũng được giới thiệu ra toàn bộ công ty và được testing nội bộ công ty mà thôi. ...