当前位置: 编程技术>移动开发
本页文章导读:
▪关于Android的多线程有关问题 关于Android的多线程问题
创建一个Handler其实跟主线程是同步的,是同一个线程,要实现多线程,必须由Looper来实现,这是Android的一个新概念如何拿到LooperHandlerThread handlerThread = new.........
▪ 随机发生制定产度数字+字母的字符串 随机产生制定产度数字+字母的字符串
package com.faithbj.shop.util;import java.util.Random;public class GeneratePresentCardID { public synchronized static String getCharacterAndNumber(int length) { String val = ""; Random random = n.........
▪ EditText焦点有关问题 EditText焦点问题
<LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px"/> <EditText android:id="@+id/text" .........
[1]关于Android的多线程有关问题
来源: 互联网 发布时间: 2014-02-18
关于Android的多线程问题
创建一个Handler其实跟主线程是同步的,是同一个线程,要实现多线程,必须由Looper来实现,这是Android的一个新概念
如何拿到Looper
HandlerThread handlerThread = new HandlerThread("handler_thread");
//在使用HandlerThread的getLooper()方法之前,必须先调用该类的start();
handlerThread.start();
MyHandler myHandler = new MyHandler(handlerThread.getLooper());
创建一个Handler其实跟主线程是同步的,是同一个线程,要实现多线程,必须由Looper来实现,这是Android的一个新概念
如何拿到Looper
HandlerThread handlerThread = new HandlerThread("handler_thread");
//在使用HandlerThread的getLooper()方法之前,必须先调用该类的start();
handlerThread.start();
MyHandler myHandler = new MyHandler(handlerThread.getLooper());
[2] 随机发生制定产度数字+字母的字符串
来源: 互联网 发布时间: 2014-02-18
随机产生制定产度数字+字母的字符串
package com.faithbj.shop.util;
import java.util.Random;
public class GeneratePresentCardID {
public synchronized static String getCharacterAndNumber(int length) {
String val = "";
Random random = new Random();
for (int i = 0; i < length; i++) {
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
if ("char".equalsIgnoreCase(charOrNum)) // 字符串
{
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写字母还是小写字母
val += (char) (choice + random.nextInt(26));
} else if ("num".equalsIgnoreCase(charOrNum)) // 数字
{
val += String.valueOf(random.nextInt(10));
}
}
System.out.println(val);
return val;
}
public static void main(String[] args) {
getCharacterAndNumber(20);
}
}
================================
UUID
public static void main(String[] args) {
String s = UUID.randomUUID().toString();
String st = s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
System.out.println(st.substring(0, 20));
}
=================================
public static String getRandomString(int length) {
if (length <= 0) {
return "";
}
char[] randomChar = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd',
'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z' };
Random random = new Random();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < length; i++) {
stringBuffer.append(randomChar[Math.abs(random.nextInt()) % randomChar.length]);
}
System.out.println(stringBuffer.toString());
return stringBuffer.toString();
}
package com.faithbj.shop.util;
import java.util.Random;
public class GeneratePresentCardID {
public synchronized static String getCharacterAndNumber(int length) {
String val = "";
Random random = new Random();
for (int i = 0; i < length; i++) {
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
if ("char".equalsIgnoreCase(charOrNum)) // 字符串
{
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写字母还是小写字母
val += (char) (choice + random.nextInt(26));
} else if ("num".equalsIgnoreCase(charOrNum)) // 数字
{
val += String.valueOf(random.nextInt(10));
}
}
System.out.println(val);
return val;
}
public static void main(String[] args) {
getCharacterAndNumber(20);
}
}
================================
UUID
public static void main(String[] args) {
String s = UUID.randomUUID().toString();
String st = s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
System.out.println(st.substring(0, 20));
}
=================================
public static String getRandomString(int length) {
if (length <= 0) {
return "";
}
char[] randomChar = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd',
'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z' };
Random random = new Random();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < length; i++) {
stringBuffer.append(randomChar[Math.abs(random.nextInt()) % randomChar.length]);
}
System.out.println(stringBuffer.toString());
return stringBuffer.toString();
}
[3] EditText焦点有关问题
来源: 互联网 发布时间: 2014-02-18
EditText焦点问题
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<EditText
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusUp="@+id/text"
android:nextFocusLeft="@+id/text"/>
解决EditText开始就获得焦点,所以在他的父层设置了焦点设置
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<EditText
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusUp="@+id/text"
android:nextFocusLeft="@+id/text"/>
解决EditText开始就获得焦点,所以在他的父层设置了焦点设置
最新技术文章: