package com.mowo;

 

import java.util.ArrayList;

import java.util.Iterator;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

import android.widget.Toast;

 

public class TestWorkspace extends Activity implements OnClickListener {

 

private Button mButton1;

private Button mButton2;

private Button mButton3;

/** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

 

        initViews();

    }

 

    @Override

    protected void onResume() {

        super.onResume();

 

TextView textView = (TextView)findViewById(R.id.hello);

        textView.setText("Android practice");

    }

 

    private void initViews() {

    

mButton1 = (Button)findViewById(R.id.button1);

mButton1.setOnClickListener(this);

 

mButton2 = (Button)findViewById(R.id.button2);

mButton2.setOnClickListener(this);

mButton3 = (Button)findViewById(R.id.button3);

mButton3.setOnClickListener(this);

    }

 

public void onClick(View view) {

 

StringBuffer buffer = new StringBuffer();

switch (view.getId()) {

case R.id.button1: 

buffer.append("我是Android ");

buffer.append("别叫我symbian");

Toast.makeText(this, buffer.toString(), Toast.LENGTH_SHORT).show();

break;

case R.id.button2:

TextCache cache = new TextCache();

buffer.append(cache.a);

buffer.append(cache.b);

Toast.makeText(this, buffer.toString(), Toast.LENGTH_SHORT).show();

break;

case R.id.button3:

// buffer.append("威哥 ");

// buffer.append("你真棒 你家的猫更棒!");

// Toast.makeText(this, buffer.toString(), Toast.LENGTH_SHORT).show();

arrayListText(buffer);

break;

default:

break;

}

}

 

final static class TextCache {

String a = "诺基亚 + 微软 = ";

String b = " 一个更比一个惨";

}

// Android ArrayList练习

public void arrayListText(StringBuffer buffer){

String mStr1 = "Hello1", mStr2 = "Hello2", mStr3 = "Hello3", mStr4 = "Hello4", mStr5 = "Hello5",

      mStr6 = "Hello6", mStr7 = "Hello7", mStr8 = "Hello8", mStr9 = "Hello9", mStr10 = "Hello10";

ArrayList strArray = new ArrayList();

strArray.add(mStr1);

strArray.add(mStr2);

strArray.add(mStr3);

strArray.add(mStr4);

strArray.add(mStr5);

strArray.add(mStr6);

strArray.add(mStr7);

strArray.add(mStr8);

strArray.add(mStr9);

strArray.add(mStr10);

StringBuffer allHello = new StringBuffer();

StringBuffer Hello13579 = new StringBuffer();

StringBuffer Hello246810 = new StringBuffer();

Iterator it = strArray.iterator();

int i = 1;

do{

if(i % 2 == 1){

Hello13579.append(it.next());

Hello13579.append(" ");

i ++;

}

else{

Hello246810.append(it.next());

Hello246810.append(" ");

i ++;

}

}while(it.hasNext());

allHello.append(Hello13579);

allHello.append(Hello246810);

buffer.append(allHello);

Toast.makeText(this, buffer.toString(), Toast.LENGTH_SHORT).show();

}

}

更多相关文章

  1. 五成Android设备要向微软支付专利费
  2. 微软和Wistron再度联手,Android和Chrome OS又成鱼肉
  3. Android设备到底侵犯了微软的什么专利
  4. 微软的 Android 计划:邪恶的天才计划或只是邪恶?
  5. Catalog Service - 解析微软微服务架构实例代码
  6. 介绍一个微软开源项目网站--CodePlex
  7. 具体分析微软的xml解析器
  8. 继 GitHub 后微软又收购了 npm

随机推荐

  1. Android ListView元素间隙线自定义渐变效
  2. Android(安卓)动画 Kotlin 教程
  3. Universal-Image-Loader(android图片缓存)
  4. android 模拟器命令
  5. Android,Harmony 及 Java 的未来
  6. android 音标乱码的一些问题
  7. android MultiDex multiDex原理(一)
  8. Android SDK23以上(包括23)无法使用httpcli
  9. [Android Studio / NDK] 如何使用javah生
  10. Android开发中用到的命令