編輯:關於Android編程
[java]
相關代碼如下:
[java]
package weibo.lixiaodaoaaa.ui;
import java.lang.reflect.Field;
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener
{
/**
* ******************騰訊微博: http://t.qq.com/lixiaodaoaaa ***************
* ******************新浪微博:http://weibo.com/lixiaodaoaaa ***************
* ******************by:lixiaodaoaaa ***********************
*/
private Context context;
private Button btn1;
private EditText et1;
public int getRandomResourceId()
{
try
{
int randmId = new Random().nextInt(7) + 1;
Field field = R.drawable.class.getDeclaredField("face_0" + randmId + "");
return field.getInt(null);
} catch (Exception e)
{
e.printStackTrace();
System.out.println("error is here");
}
return 0;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initAllDatas();
for (int i = 0; i < 100; i++)
{
btn1.performClick();
}
}
private void initAllDatas()
{
context = MainActivity.this;
btn1 = (Button) findViewById(R.id.btn1);
et1 = (EditText) findViewById(R.id.et1);
btn1.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.btn1:
ImageSpan imageSpan = new ImageSpan(context, BitmapFactory.decodeResource(getResources(),
getRandomResourceId()));
SpannableString spannableString = new SpannableString("face");
spannableString.setSpan(imageSpan, 0, spannableString.length(), SpannableString.SPAN_MARK_MARK);
et1.append(spannableString);
break;
default:
break;
}
}
}
package weibo.lixiaodaoaaa.ui;
import java.lang.reflect.Field;
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener
{
/**
* ******************騰訊微博: http://t.qq.com/lixiaodaoaaa ***************
* ******************新浪微博:http://weibo.com/lixiaodaoaaa ***************
* ******************by:lixiaodaoaaa ***********************
*/
private Context context;
private Button btn1;
private EditText et1;
public int getRandomResourceId()
{
try
{
int randmId = new Random().nextInt(7) + 1;
Field field = R.drawable.class.getDeclaredField("face_0" + randmId + "");
return field.getInt(null);
} catch (Exception e)
{
e.printStackTrace();
System.out.println("error is here");
}
return 0;
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initAllDatas();
for (int i = 0; i < 100; i++)
{
btn1.performClick();
}
}
private void initAllDatas()
{
context = MainActivity.this;
btn1 = (Button) findViewById(R.id.btn1);
et1 = (EditText) findViewById(R.id.et1);
btn1.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.btn1:
ImageSpan imageSpan = new ImageSpan(context, BitmapFactory.decodeResource(getResources(),
getRandomResourceId()));
SpannableString spannableString = new SpannableString("face");
spannableString.setSpan(imageSpan, 0, spannableString.length(), SpannableString.SPAN_MARK_MARK);
et1.append(spannableString);
break;
default:
break;
}
}
}
Introduction 由於每個應用程序都運行在自己的進程空間,並且可以從應用程序UI運行另一個服務進程,而且經常會在不同的進程間傳遞對象。在Android平台,一個進
今天主要介紹一下Android的一個原生組件-WebView。在Api中關於這個類的介紹大致就是這是一個可以顯示網頁的視圖,如:webView.loadUrl("
視差效果是什麼?所謂的視差效果在Web設計和移動應用中都非常常見,我們在一些主要的平台都可以發現它的身影,從Windows Phone到iOS乃至Android。按照維基
據說Android最推薦的是在ViewPager中使用FragMent,即ViewPager中的頁面不像前面那樣用LayoutInflater直接從布局文件加載,而是一個