2011年10月19日星期三

Galaxy Nexus/Android 4.0 發佈會全記錄


谷歌/三星推出 Android 4.0 冰淇淋三明治 - 2011年10月19日,香港



2011年10月15日星期六

指定 Drawable 設定為列表視圖(ListView)的背景

指定 Drawable 設定為列表視圖(ListView)的背景
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/icon"
android:cacheColorHint="#00000000" />


相關文章:
- 設定列表視圖(ListView)的背景顏色

設定列表視圖(ListView)的背景顏色

在佈局文件的 XML 中, 可通過列表視圖(ListView)的 android:background 和 android:cacheColorHint 以設定列表視圖的背景顏色.

設定列表視圖(ListView)的背景顏色

<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF500000"
android:cacheColorHint="#00000000" />



相關文章:
- 指定 Drawable 設定為列表視圖(ListView)的背景



2011年10月14日星期五

2011年10月19日香港: Google + Samsung 正式公佈雪糕三明治(Ice Cream Sandwich)

Android 的官方YouTube頻道(http://www.youtube.com/android)已更新顯示:
10/19/2011 - 10 AM Hong Kong Time (HKT)

2011年10月19日香港: Google + Samsung 正式公佈雪糕三明治(Ice Cream Sandwich)

Live: YouTube.com/Android, 10/19/11, 10AM, Hong Kong Time (HKT)



Android谷歌翻譯(Google Translate)的對話模式(Conversation Mode)現支持更多語言, 包括中文.

除了原有的英語和西班牙語,Android谷歌翻譯(Google Translate)的對話模式(Conversation Mode)現在也支持巴西葡萄牙語,捷克語,荷蘭語,法語,德語,意大利語,日語,韓語,中文普通話,波蘭,俄羅斯和土耳其。

詳情: http://googlemobile.blogspot.com/2011/10/start-conversation-with-google.html



Android Market的下載鏈接

讀取多選項列表視圖(Read multiple choice ListView)

讀取多選項列表視圖(Read multiple choice ListView)

package com.MultiChoiceList;

import android.app.Activity;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MultiChoiceList extends Activity {

ListView list;
TextView selection;

String[] options = {"Option 1", "Option 2", "Option 3",
"Option 4", "Option 5", "Option 6"};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list = (ListView)findViewById(R.id.list);
selection = (TextView)findViewById(R.id.selection);

ArrayAdapter<String> adapter
= new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
options);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

list.setAdapter(adapter);

list.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
selection.setText(ReadSelection());
}});
}

String ReadSelection(){

String selected = "";
int cntChoice = list.getCount();
SparseBooleanArray sparseBooleanArray = list.getCheckedItemPositions();

for(int i = 0; i < cntChoice; i++){
if(sparseBooleanArray.get(i)) {
selected += list.getItemAtPosition(i).toString() + "\n";
}
}

return selected;
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>




2011年10月13日星期四

含多項選擇(multiple choice)的列表視圖(ListView)

通過 setChoiceMode(ListView.CHOICE_MODE_MULTIPLE) 以及 android.R.layout.simple_list_item_multiple_choice 佈局, 可以設定列表視圖(ListView)為多選項.

實例:

含多項選擇(multiple choice)的列表視圖(ListView)

package com.MultiChoiceList;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MultiChoiceList extends Activity {

ListView list;

String[] options = {"Option 1", "Option 2", "Option 3",
"Option 4", "Option 5", "Option 6"};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list = (ListView)findViewById(R.id.list);

ArrayAdapter<String> adapter
= new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
options);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

list.setAdapter(adapter);
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>



相關文章:
- 讀取多選項列表視圖(Read multiple choice ListView)



2011年10月12日星期三

2011年10月2日星期日

從 SD Card 中讀取圖像檔案

從 SD Card 中讀取圖像檔案

package com.AndroidLoadFromSD;

import java.io.File;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class AndroidLoadFromSD extends Activity {

ImageView Image;
Button LoadButton;
Bitmap bmImage;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Image = (ImageView)findViewById(R.id.image);
LoadButton = (Button)findViewById(R.id.load);

LoadButton.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

String extStorage = Environment.getExternalStorageDirectory().toString();
String file = new File(extStorage, "myFile.PNG").toString();
Bitmap bm = BitmapFactory.decodeFile(file);
Image.setImageBitmap(bm);

Toast.makeText(AndroidLoadFromSD.this,
extStorage+"/myFile.PNG",
Toast.LENGTH_LONG).show();

}});
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/load"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load Image (myFile.PNG)"
/>
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>


相關文章:
- 儲存圖像到 SD Card 中



2011年10月1日星期六

儲存圖像到 SD Card 中

儲存圖像到 SD Card 中

package com.AndroidSaveOnSD;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class AndroidSaveOnSD extends Activity {

ImageView Image;
Button SaveButton;
Bitmap bmImage;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Image = (ImageView)findViewById(R.id.image);
SaveButton = (Button)findViewById(R.id.save);

bmImage = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
Image.setImageBitmap(bmImage);

SaveButton.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

String extStorage = Environment.getExternalStorageDirectory().toString();
File file = new File(extStorage, "myFile.PNG");

try {
OutputStream outStream = new FileOutputStream(file);
bmImage.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Toast.makeText(AndroidSaveOnSD.this,
extStorage+"/myFile.PNG",
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(AndroidSaveOnSD.this,
e.toString(),
Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(AndroidSaveOnSD.this,
e.toString(),
Toast.LENGTH_LONG).show();
}

}});
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Save Image (myFile.PNG)"
/>
</LinearLayout>


注意須修改 AndroidManifest.xml 添加 "android.permission.WRITE_EXTERNAL_STORAGE" 權限.

相關文章:
- 從 SD Card 中讀取圖像檔案