編輯:關於Android編程
要實現的效果是點擊加按鈕就購買分數自動加一,同時計算合計的總計
先共享一份colors.xml的數據,比較全面,可以根據需要添加
#b0000000 #f4f4f4 #00000000 #4ebcd3 #2D2F31 #ffffff #cccccc #fcfcfc #0099ff #f9f9f9 #bababa #f0f0f0 #0099ff #7cbe28 #fafafa #cccccc #999999 #666666 #333333 #00338B #003F97 #0B4CA4 #f08300 #61A30C #80C22C #95D741 #CDCEC9 #C3C3C3 #2e000000 #f2f2f2 #de6838 #333333 #666666 #999999 #fafafa #666666 #cccccc #cccccc #02367D #0F438A #EFEFEF #EB321B #60000000 #b0000000 #ff000000 #ffff0000 #c0ffff00 #33B5E5 #FFFFFF #000000 #CCCCCC #EEEEEE #FFFFFF #000000 #CC0000 #CCCCCC #FFFFFF #FFFFF0 #FFFFE0 #FFFF00 #FFFAFA #FFFAF0 #FFFACD #FFF8DC #FFF5EE #FFF0F5 #FFEFD5 #FFEBCD #FFE4E1 #FFE4C4 #FFE4B5 #FFDEAD #FFDAB9 #FFD700 #FFC0CB #FFB6C1 #FFA500 #FFA07A #FF8C00 #FF7F50 #FF69B4 #FF6347 #FF4500 #FF1493 #FF00FF #FF00FF #FF0000 #FDF5E6 #FAFAD2 #FAF0E6 #FAEBD7 #FA8072 #F8F8FF #F5FFFA #F5F5F5 #F5F5DC #F5DEB3 #F4A460 #F0FFFF #F0FFF0 #F0F8FF #F0E68C #F08080 #EEE8AA #EE82EE #E9967A #E6E6FA #E0FFFF #DEB887 #DDA0DD #DCDCDC #DC143C #DB7093 #DAA520 #DA70D6 #D8BFD8 #D3D3D3 #D3D3D3 #D2B48C #D2691E #CD853F #CD5C5C #C71585 #C0C0C0 #BDB76B #BC8F8F #BA55D3 #B8860B #B22222 #B0E0E6 #B0C4DE #AFEEEE #ADFF2F #ADD8E6 #A9A9A9 #A9A9A9 #A52A2A #A0522D #9932CC #98FB98 #9400D3 #9370DB #90EE90 #8FBC8F #8B4513 #8B008B #8B0000 #8A2BE2 #87CEFA #87CEEB #808080 #808080 #808000 #800080 #800000 #7FFFD4 #7FFF00 #7CFC00 #7B68EE #778899 #778899 #708090 #708090 #6B8E23 #6A5ACD #696969 #696969 #66CDAA #6495ED #5F9EA0 #556B2F #4B0082 #48D1CC #483D8B #4682B4 #4169E1 #40E0D0 #3CB371 #32CD32 #2F4F4F #2F4F4F #2E8B57 #228B22 #20B2AA #1E90FF #191970 #00FFFF #00FFFF #00FF7F #00FF00 #00FA9A #00CED1 #00BFFF #008B8B #008080 #7cbe28 #006400 #004299 #0000CD #00008B #000080 #000000
自定義的dimens.xml
100dp 1dp 48dp 16dp 16dp 18sp 15sp 13sp 11sp 9sp 17sp 67dp 50dp 49dp 53dp 55dp 44dp 45dp 40dp 67dp 80dp 400dp 100dp 120dp 45dp 30dp 16dp 270dp 60dp 12dp 10dp 3dp 155dp 174dp 87dp 72dp 6dp 3dp 4dp 6dp 12dp 10dp 14dp 6dp 9dp 8sp 10sp 12sp 14sp 16sp 18sp 20sp 22sp 24sp 26sp 28sp
text_angle_gray.xml
text_angle.xml,是實現圓角效果的
然後,實現這個ui
業務實現
package com.tsc.activities; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.tsc.Constant; import com.tsc.fragment.CalendarFragment; import com.tsc.service.AddOrderService; /** * 預定旅游服務的Activity類 * */ public class ReserveActivity extends Activity implements OnClickListener{ private TextView tv_back;//返回的TextView private TextView tv_price;//單價的TextView private TextView tv_total_price;//總價的TextView private TextView tv_clear;//清空的TextView private TextView tv_go_to_pay;//去支付的TextView private TextView tv_intro;//顯示線路名稱的TextView private TextView tv_num;//顯示票數的TextView private TextView tv_reduce;//點擊可以票數減1 private TextView tv_add;//點擊可以票數加1 private EditText et_time;//日歷EditText,功能測試ing private Context context;//Context private String account;//獲取從主界面傳來的賬號 private double totalPrice = 0.00;//總價錢 private int totalCount = 0;//總票數 private String priceString;//單件,String類型的 CalendarFragment calendarFragment;//日歷的Fragment int lineID=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //設置無標題 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_reserve); initView(); initEvents(); } /** * 初始化操作 */ public void initView(){ context = this; //獲取賬號 account = getIntent().getStringExtra("account"); tv_back = (TextView)findViewById(R.id.tv_back);//返回 tv_price = (TextView)findViewById(R.id.tv_price);//顯示單價的TextView tv_total_price = (TextView)findViewById(R.id.tv_total_price);//顯示總價錢的TextViw tv_clear = (TextView)findViewById(R.id.tv_clear);//點擊清空,總價置0 tv_go_to_pay = (TextView)findViewById(R.id.tv_go_to_pay);//去付款 tv_num = (TextView)findViewById(R.id.tv_num);//顯示票數的TextView tv_reduce = (TextView)findViewById(R.id.tv_reduce);//點擊票數減1 tv_add = (TextView)findViewById(R.id.tv_add);//點擊票數加1 et_time = (EditText)findViewById(R.id.et_time);//出游時間 String tourism_time = getIntent().getExtras().getString("tourism_time"); et_time.setText(tourism_time); double price = getIntent().getExtras().getDouble("price"); totalCount=1; totalPrice = price; tv_price.setText("¥"+price); tv_total_price.setText("¥"+price); priceString = tv_price.getText().toString().replace("¥", "");//獲取單價 tv_num.setText("1"); tv_go_to_pay.setText("結算(1)"); lineID=getIntent().getExtras().getInt("ID"); String name = getIntent().getExtras().getString("name"); tv_intro=(TextView)findViewById(R.id.tv_intro);//線路名稱 tv_intro.setText(name); } /** * 事件操作 */ public void initEvents(){ tv_back.setOnClickListener(this); tv_clear.setOnClickListener(this); tv_go_to_pay.setOnClickListener(this); tv_reduce.setOnClickListener(this); tv_add.setOnClickListener(this); et_time.setOnClickListener(this); } @Override public void onClick(View v) { AlertDialog alert; switch (v.getId()) { case R.id.et_time: break; case R.id.tv_go_to_pay: if (totalCount == 0) { Toast.makeText(context, "請選擇要預定的旅游服務", Toast.LENGTH_LONG).show(); return; } alert = new AlertDialog.Builder(context).create(); alert.setTitle("操作提示"); alert.setMessage("總計:\n" + totalCount + "張票\n" + totalPrice + "元"); alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { return; } }); alert.setButton(DialogInterface.BUTTON_POSITIVE, "確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String countString = String.valueOf(totalCount);//票數 String priceString = String.valueOf(totalPrice);//單價 String lineIdString = Integer.toString(lineID);//旅游路線ID String timeString = et_time.getText().toString();//出游時間 //執行異步任務 new AddOrderAsyncTask().execute(Constant.URL_AddOrder,account,countString,priceString,lineIdString,timeString); } }); alert.show(); break; case R.id.tv_clear: if (totalCount == 0) { Toast.makeText(context, "請選擇要取消預定的旅游服務", Toast.LENGTH_LONG).show(); return; } alert = new AlertDialog.Builder(context).create(); alert.setTitle("操作提示"); alert.setMessage("您確定要取消預定的旅游服務嗎?"); alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { return; } }); alert.setButton(DialogInterface.BUTTON_POSITIVE, "確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { totalCount = 0; totalPrice = 0.00; tv_num.setText("0"); tv_total_price.setText("¥0.00"); tv_go_to_pay.setText("結算(0)"); } }); alert.show(); break; case R.id.tv_back: this.finish(); break; case R.id.tv_reduce: if(totalCount >= 1){ totalCount--; tv_num.setText(String.valueOf(totalCount)); totalPrice = Double.parseDouble(priceString)*totalCount; tv_total_price.setText(String.valueOf(totalPrice)); tv_go_to_pay.setText("結算("+totalCount+")"); }else if(totalCount <= 0){ Toast.makeText(context, "數量不可以小於0哦!", 1).show(); } break; case R.id.tv_add: totalCount++; tv_num.setText(String.valueOf(totalCount)); totalPrice = Double.parseDouble(priceString)*totalCount; tv_total_price.setText(String.valueOf(totalPrice)); tv_go_to_pay.setText("結算("+totalCount+")"); break; } } /** * *簡介 AsyncTask可以使得使用UI線程變的更容易更適當,它可以在後台運行一些操作然後在UI上展現,不用操作具體的線程和handlers 一個 asynchronous task包括三種基本類型(調用參數,進度和結果),和四個步驟(調用開始,在後台運行,處理進度,結束) ), and most often will override a second one (onPostExecute(Result).) 使用方法描述 Asynchronous Task必須是作為一個子類來使用, task實例必須在UI線程創建 execute(Params...)必須在UI線程調用 不要手工調用onPreExecute(), onPostExecute(Result), doInBackground(Params...), onProgressUpdate(Progress...)。 task只可以execute一次,執行多次就報異常 * */ class AddOrderAsyncTask extends AsyncTask{ @Override protected String doInBackground(String... params) { AddOrderService addOrderService = new AddOrderService(); String retStr = addOrderService.addOrder(params[0], params[1],params[2],params[3],params[4],params[5]); return retStr; } @Override protected void onPostExecute(String result) { // TODO Auto-generated method stub super.onPostExecute(result); if(result.equals("error")){ Toast.makeText(getApplicationContext(), "提交訂單失敗!", 1).show(); }else if(result.equals("success")){ Toast.makeText(getApplicationContext(), "提交訂單成功!", 1).show(); ReserveActivity.this.finish(); } } } }
一、簡介 地圖控件自v2.3.5版本起,支持多實例,即開發者可以在一個頁面中建立多個地圖對象,並且針對這些對象分別操作且不會產生相互干擾。 文件名:D
SharedPreference:1.是一種輕型的數據存貯方式2.本質是基於xml文件存貯key_value鍵值對數據3.通常用來存貯一些簡單的配置信息(密碼,窗口狀態,
Android開發中常用的數據庫有5個:1.OrmLiteOrmLite 不是 Android 平台專用的ORM框架,它是Java ORM。支持JDBC連接,Spring
這篇文章篇幅較長,可以使用版權聲明下面的目錄,找到感興趣的進行閱讀目錄 3.1 Android Studio使用初探 Project面板 Stucture面板 Andro