Professional Documents
Culture Documents
Project : RestaurantRandom
<TextView
android:id = "@+id/textView"
android:layout_width = "wrap_content"
android:layout_height = "70dip"
android:textSize = "10pt" >
</TextView>
<Button
android:id = "@+id/button"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_marginTop = "30dip"
android:text = "Shaker!" >
</Button>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity = "center" >
<Button
android:id = "@+id/button"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_marginTop = "30dip"
android:text = "Shaker!" >
</Button>
textView = (TextView)findViewById(R.id.textView);
button = (Button)findViewById(R.id.button);
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textView.setText(getRestaurantName());
}
});
TextView textView;
Button button;
textView = (TextView)findViewById(R.id.textView);
button = (Button)findViewById(R.id.button);
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textView.setText(getRestaurantName());
}
});
Math.random()*list.length-1
2. เอาค่าที่ สุ่มได้มาปัดเศษ จะได้ว่า
Math.round( Math.random()*list.length-1 )
3. เนื่อง จากค่าที่ได้เป็น Double เราจึงต้องแปลงเป็น Integer ก่อน จะได้ว่า
4. ต่อมาคือ การหาชื่อ ร้านอาหารจาก index ที่เราคิดมา จะได้ว่า
list[ (int) Math.round( Math.random()*list.length-1 ) ];
drbomkung@gmail.com