http://tech.it168.com/a2009/0907/675/000000675155_3.shtml
http://blog.sina.com.cn/s/blog_62c194760100ggnu.html~type=v5_one&label=rela_nextarticle
package com.android.AsynctaskTest;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
public class AsynctaskTest extends Activity {
String imageUrl = "http://hiphotos.baidu.com/baidu/pic/item/7d8aebfebf3f9e125c6008d8.jpg";
String param="";
ProgressBar mypb;
ImageView mimg;
Button btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mypb =(ProgressBar)findViewById(R.id.pgb);
mimg =(ImageView)findViewById(R.id.wallpaper);
btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new myAsynctask().execute(param);
}
});
}
Bitmap getImageFromNetwork() {
URL myFileUrl = null;
Bitmap bitmap = null;
try {
myFileUrl = new URL(/blog_article/imageUrl/index.html);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(bitmap==null);
System.out.println(myFileUrl.toString());
return bitmap;
}
class myAsynctask extends AsyncTask<String ,Integer ,Bitmap >{
@Override
protected Bitmap doInBackground(String... params) {
// TODO Auto-generated method stub
Bitmap bitmap=getImageFromNetwork();
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
if(result!=null){
mimg.setImageBitmap(result);
}
else
mimg.setBackgroundResource(R.drawable.icon);
super.onPostExecute(result);
mypb.setVisibility(View.GONE);
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
mypb.setProgress(values[0]);
super.onProgressUpdate(values);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
mypb.setVisibility(View.VISIBLE);
mypb.setProgress(0);
super.onPreExecute();
}
}
}
http://aijiawang-126-com.iteye.com/blog/592643
两个视频介绍关于android 手机中使用了NFC技术:
[url]http://cnbeta.com/articles/132634.htm
[/url]
Smart Posters(转自:http://www.theregister.co.uk/2006/10/11/nfc_smart_posters/
he NFC Forum has just published the Smart Posters component of its short-range-radio standard, while Nokia continues with large-scale trials of the technology.
Smart Posters are signs, billboards, or any other form of advertising which will incorporate a passive (unpowered) NFC Tag, from which a user can extract data by touching it with their NFC-enabled handset. The data could be a free ringtone, a URL, or even the configuration for a local Wi-Fi hotspot.
But Smart Posters are much more important to the NFC than a mechanism for giving away a few tones or setting up networking. Smart Posters have been promoted as the mechanism by which network operators can make money out of NFC. The idea is that all those extracted URLs will generate lots of data traffic for the operator - which would be fine, except that an increasing proportion of network operators are charging a flat rate for data, so more traffic is a burden, not a profit.
Meanwhile, Nokia is running yet more trials to show how great NFC is. This time it's public transport in Tampere, Finland, in conjunction with TeliaSonera and TietoEnator. We have to assume that Nokia has an awful lot of NFC-equipped 3220s lying around the place, as it doesn't seem to have bothered to equip any more up-to-date handsets with the technology and this trial, as so many others, will be using the three year old phone.
With the Smart Poster specification completed, Nokia and its friends desperately need to prove that NFC can make money for network operators, who will be expected to subsidise handsets sporting the technology, but reducing bus queues in Tampere is not going to achieve that.
前言
在一个主界面中做Activity切换一般都会用TabActivity,使用方便,Activity互相之间相对独立,但是可定制性不强,而且修改起来很麻烦。当然也可以把layout分开,把逻辑代码全写在主界面的逻辑代码中,但是很明显可维护性相当差,这里通过ActivityGroup来解决这个问题。
要求点击底部不同图片按钮切换不同的Activity,并在中间显示Activity对应的ContentView
二、 实现代码
2.1 layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="fill_parent"> <LinearLayout android:gravity="center_horizontal" android:background="@drawable/myinfor2" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/cust_title" android:textColor="@android:color/white" android:textSize="28sp" android:text="模块1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> </LinearLayout> <!-- 中间动态加载View --> <ScrollView android:measureAllChildren="true" android:id="@+id/containerBody" android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"> </ScrollView> <LinearLayout android:background="@android:color/black" android:layout_gravity="bottom" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <!-- 功能模块按钮1 --> <ImageView android:id="@+id/btnModule1" android:src="/blog_article/@android_drawable/ic_dialog_dialer/index.html" android:layout_marginLeft="7dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!-- 功能模块按钮2 --> <ImageView android:id="@+id/btnModule2" android:src="/blog_article/@android_drawable/ic_dialog_info/index.html" android:layout_marginLeft="7dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!-- 功能模块按钮3 --> <ImageView android:id="@+id/btnModule3" android:src="/blog_article/@android_drawable/ic_dialog_alert/index.html" android:layout_marginLeft="7dp" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
2.2 TestView.java
/** * 使用ActivityGroup来切换Activity和Layout * @author 农民伯伯 * @version 2010-9-7 * */ public class TestView extends ActivityGroup { private ScrollView container = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 隐藏标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置视图 setContentView(R.layout.layout); container = (ScrollView) findViewById(R.id.containerBody); // 模块1 ImageView btnModule1 = (ImageView) findViewById(R.id.btnModule1); btnModule1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { container.removeAllViews(); container.addView(getLocalActivityManager().startActivity( "Module1", new Intent(TestView.this, ModuleView1.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView()); } }); // 模块2 ImageView btnModule2 = (ImageView) findViewById(R.id.btnModule2); btnModule2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { container.removeAllViews(); container.addView(getLocalActivityManager().startActivity( "Module2", new Intent(TestView.this, ModuleView2.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView()); } }); // 模块3 ImageView btnModule3 = (ImageView) findViewById(R.id.btnModule3); btnModule3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { container.removeAllViews(); container.addView(getLocalActivityManager().startActivity( "Module3", new Intent(TestView.this, ModuleView3.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView()); } }); } }