Time of Update: 2018-12-04
1、這幾天要實現硬鍵盤選擇GridView中的Item來執行不同的操作,可糾結了幾天終不得解,摸索了很久也在網上找了很多資料。最後,終於有了眉目,基本實現了其功能。寫此文來總結一下。2、首先是GridView資料的添加:gridview_item.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Time of Update: 2018-12-04
昨天介紹了ArrayAdapter的使用,今天介紹一下更加實用的一點,對它進行重寫,滿足自己的個人化設計需要.ArrayAdapter(數組適配器)一般用於顯示一行文本資訊,所以比較容易。public ArrayAdapter(Context context,int textViewResourceId, List<T>
Time of Update: 2018-12-04
關於Socket,百度百科是這麼說的:什麼是socket 所謂socket通常也稱作"通訊端",應用程式通常通過"通訊端"向網路發出請求或者應答網路請求。以J2SDK-1.3為例,Socket和ServerSocket類庫位於java
Time of Update: 2018-12-04
一、最近遇到了一個問題,是關於Toast多次顯示時會過慢的問題,系統內建的toast顯示時間只有2秒或3秒兩種,當然使用toast.cancel()的方法取消掉前面那個toast,但是如果多次點擊顯示toast,那麼有一段時間是什麼都沒有顯示的,最後只顯示最後點擊顯示的toast。這遠遠達不到要求。在網上搜了下相關的解決方案:1、使用反射機制,有這麼一個例子:Toast toast = Toast.makeText(this, "永不關閉的Toast",
Time of Update: 2018-12-04
Time of Update: 2018-12-04
在上一篇博文中,簡單介紹了Socket的簡單通訊,這篇博文中將針對它進行簡單的運用。接下來的例子是參考《Android應用開發揭秘》,不過上面有些小問題,例如字元編碼問題。下面直接看下實現過程。1、伺服器:import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import
Time of Update: 2018-12-04
先上代碼:dbHelper = new DatabaseHelper(Alarm.this, "idea.sql");SQLiteDatabase db = dbHelper.getReadableDatabase();Cursor cursor = db.query("user", new String[] {"_id","mtext","mtime"}, "_id=?",new String[] {NoteActivity.AlarmIndex+""}, null,null,
Time of Update: 2018-12-04
1、在Android系統中,有時候在文字框中輸入文字後,操作按鈕被IME遮擋了,不得不關閉IME才可以繼續操作。預設時時這樣的,很麻煩。2、於是,查了一些資料,終於找到方法。先來看下代碼與效果:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Time of Update: 2018-12-04
1、現在很多的應用都會提供白天和黑夜兩種閱讀方式,其實也就是調解下螢幕的亮度。其實是很簡單的,只需要一些簡單的代碼即可。2、實現過程:// 螢幕亮度WindowManager.LayoutParams lp = getWindow().getAttributes();lp.screenBrightness = Constant_Src.brightness;getWindow().setAttributes(lp);其中Constant_Src.brightness是一個浮點型,它的值為0f到1
Time of Update: 2018-12-04
1、先看下listview適配器mlistItemAdapter = new SimpleAdapter(getApplicationContext(),mlistItem,// 資料來源R.layout.listviewitem, new String[] { "mtext", "mtime" },new int[] { R.id.ItemText, R.id.ItemTime });2、index索引int index = 0;// 長按刪除指定資料的索引3、長按得到index//
Time of Update: 2018-12-04
1、Service介紹官方解釋:A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background
Time of Update: 2018-12-04
Android [1] 張國威:Android從入門到提高系列前面寫了十四篇關於介面的入門文章,大家都看完和跟著練習之後,對於常用的Layout和View都會有一定的瞭解了,接下來的文章就不再強調介紹介面了,而是針對具體的常見功能而展開。[2] 懶骨頭:《Android Dev Guide》系列教程翻譯文章1-18本系列文章為Android
Time of Update: 2018-12-04
一、使用MediaPlayer來播放音頻檔案存在一些不足:例如:資源佔用量較高、延遲時間較長、不支援多個音頻同時播放等。這些缺點決定了MediaPlayer在某些場合的使用方式不會很理想,所有,一般的遊戲開發都是用的Soundpool。在沒有瞭解Soundpool之前,我也是使用的普通的MediaPlayer進行檔案播放,但這個方法不適合用於遊戲開發,因為遊戲裡面經常要同時播放幾個音樂檔案,用過MediaPlayer的朋友都該知道,它是不支援即時播放多個聲音的,而且還會出現或多或少的延遲,尤其是
Time of Update: 2018-12-04
我們都知道,一般下載的flash遊戲(基於鍵盤來玩的那一種),他們的遊戲控制方式一般都是上下左右鍵。現在我想用其他的鍵來替代上下左右鍵。下面是實現過程:1、由於是鍵盤控制,所以少不了onKeyDown與onKeyUp的使用。要想在遊戲中改變控制的索引值,就必須重寫下WebView(這裡使用WebView播放flash)。重寫WebViewpublic class mWebView extends WebView {public mWebView(Context context,
Time of Update: 2018-12-04
使用Android混淆器proguard.cfg來防止程式被反編譯,也其實就是將變數的名稱混淆一下,降低程式的可讀性使用步驟:1.default.properties檔案中添加一行proguard.config=proguard.cfg, 例如以下是我的default.properties的源檔案# This file is automatically generated by Android Tools.# Do not modify this file -- YOUR CHANGES
Time of Update: 2018-12-04
關於AppWidgetProvider我就不多說了,這個可以去官方文檔看下。最近因為碰到一個問題,在xml中使用<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/widget" android:minHeight="120dip" android:minWidth="120dip" android:
Time of Update: 2018-12-04
直接上代碼:java檔案public class tuya extends Activity {/** Called when the activity is first created. */private SurfaceView surfaceView = null;private SurfaceHolder sfh = null;private ImageButton clean = null;private Paint mpaint = null;private float oldx =
Time of Update: 2018-12-04
本來原始碼如下:List<Restaurant> model; //自訂的一個List資料,儲存的是自訂的類 LunchListAdapter adapter;//自訂的一個ListView的適配器......//省略class onSavaLis implements OnClickListener{//Button save的監聽器,點擊之後往model裡面添加資料Restaurant r = new
Time of Update: 2018-12-04
在實際的應用程式開發中,我們有時需要把 Activity 設定成全螢幕顯示,一般情況下,可以通過兩種方式來設定全螢幕顯示效果。其一,通過在代碼中可以設定,其二,通過manifest設定檔來設定全屏。 其一:在代碼中設定(如下)[c-sharp] view plaincopypublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
Time of Update: 2018-12-04
今天在網上看到ExpandableListView的效果,之前一直沒發現。感覺挺好用的,借用下別人的例子。主檔案 .javaimport java.util.ArrayList;import java.util.List;import android.app.ExpandableListActivity;import android.os.Bundle;import android.view.Gravity;import android.view.View;import