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. Android(安卓)source download for linux
  3. android 自动更新apk版本
  4. Android(安卓)sdk content loader 0% - mac
  5. 运行时改变Button的android:drawableTop
  6. Android(安卓)开源项目
  7. 第三课:android发送短信
  8. Android(安卓)获取路径目录方法
  9. 【063】◀▶ Android(安卓)(I) - 控件和布局

随机推荐

  1. android琐碎记四
  2. How to change an Android app's name?
  3. 同样line-height下ios和Android显示不一
  4. Android小知识7
  5. android 2.3 修改 statusbar
  6. Android(安卓)拦截音量键,控制系统媒体音
  7. Android调用系统默认浏览器访问的方法
  8. Android新控件MotionLayout介绍(三)
  9. Android Notification 通知
  10. android 开发问题集,android问题总结,and