編輯:關於Android編程
public class CustomDialog { private AlertDialog.Builder builder; private Context context; public CustomDialog(Context context) { // TODO Auto-generated constructor stub this.context = context; } public void createDialog(String buttontext, String title, String message, final CallBack callBack) { builder = new AlertDialog.Builder(context); builder.setTitle(title); builder.setMessage(message); builder.setPositiveButton(buttontext, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub callBack.isConfirm(true); } }); builder.create().show(); } public interface CallBack { public void isConfirm(boolean flag); } public void createToasts(String message,LayoutInflater layoutInflater) { // Toast.makeText(context, message, Toast.LENGTH_LONG).show(); View view = layoutInflater.inflate(R.layout.toast, null); TextView textView = (TextView)view.findViewById(R.id.text); textView.setText(message); Toast toast = new Toast(context); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(view); toast.show(); } }
public class MainActivity extends Activity { private Button button; private Button button2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) this.findViewById(R.id.button1); button2 = (Button) this.findViewById(R.id.button2); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub CustomDialog dialog = new CustomDialog(MainActivity.this); dialog.createDialog("確定", "提示", "您確定要刪除嗎?", new CallBack() { @Override public void isConfirm(boolean flag) { // TODO Auto-generated method stub System.out.println("----->>" + flag); if (flag) { //dosomething.....判斷執行業務邏輯 } } }); } }); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub CustomDialog dialog = new CustomDialog(MainActivity.this); // LayoutInflater layoutInflater = getLayoutInflater(); dialog.createToasts("網絡有有異常!!",getLayoutInflater()); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
在做布局時,經常有些部分是重復的,比如title或者foot的地方,最簡單的辦法當然是直接復制過去, 這裡介紹include的用法,有過c++或者c經驗的
本demo是《Android智能穿戴設備開發指南》書中的一塊內容,實現了兩台手機基於藍牙進行即時通訊的功能。demo演示如下:結構圖主要代碼MainActivity:啟動
心情來這家公司也有差不多一年的時間了,項目中網絡請求部分用到的是Volley,之前都是從別人的博客中了解Volley的用法和他的工作原理。如今項目也寫的差不多了,回想起來
手機百度雲怎麼修改默認下載位置?如果一直把文件下載百度雲手機客戶端默認的位置恐怕手機的內存條要變紅了,所以更改百度雲手機客戶端的默認下載位置是很必要的,將百