设置当前activity的属性,两种方式:1.在manifest文件中给指定的activity增加属性
android:theme="@android:style/Theme.Light"。2.在程序中增加语句setTheme(R.style.Theme_ Light);
注意要判断Cursor返回的记录是否为空~~ 之前给这个问题卡了很久~ 囧
public SimpleAdapter getlistItem(Cursor c){ ArrayList<HashMap<String,Object>> listItem = new ArrayList<HashMap<String,Object>>(); if (c.getCount()==0) //一定要加这个判断条件~,否则出现cursor越界 return null; c.moveToFirst(); do { int index; HashMap<String, Object> map = new HashMap<String, Object>(); index = c.getColumnIndex(Todolist.TITLE); map.put(Todolist.TITLE, c.getString(index)); index = c.getColumnIndex(Todolist.BEGIN_TIME); map.put(Todolist.BEGIN_TIME,convertTime(c.getLong(index))); index = c.getColumnIndex(Todolist.STATUS); map.put(Todolist.STATUS, drawble[c.getInt(index)]); listItem.add(map); } while (c.moveToNext()); adapter = new SimpleAdapter(this, listItem, R.layout.list_item, new String[]{Todolist.TITLE,Todolist.BEGIN_TIME,Todolist.STATUS}, new int[]{R.id.TextView01,R.id.TextView02,R.id.ImageView01}); return adapter; }
还有就是查询设定某些条件返回的cursor,不能直接就获取返回记录的的值,要先moveToFirst()
例如:
PersonActivity.gategory = PersonActivity.dc.query(CategoryList.projection,"_id="+tag, null, null); /* * 记得移动光标,因为刚开得到的cursor没有指向任何记录位置的~ 惨痛的教训! */ PersonActivity.gategory.moveToFirst(); showtype.setText("类型:"+PersonActivity.gategory.getString(1));
还有Cursor的requery()和deactivate()两个方法的用途
List<SendMessage> msgList = new ArrayList<SendMessage>();
try{
open();
Cursor cur = dbConn.query(true, NETWORK_TABLE, new String[] { _ID , DOWN_SIZE ,
TIME_LONG , ADDRESS}, IS_SEND + " = 1" , null, null, null, null, null);
if(null != cur && cur.getCount() > 0){
SendMessage sendMsg = new SendMessage();
cur.moveToFirst();
while(cur.isAfterLast()){
sendMsg.setId(cur.getString(cur.getColumnIndexOrThrow(_ID)));
sendMsg.setDownSize(cur.getString(cur.getColumnIndexOrThrow(DOWN_SIZE)));
sendMsg.setTimeLong(cur.getString(cur.getColumnIndexOrThrow(TIME_LONG)));
sendMsg.setAddress(cur.getString(cur.getColumnIndexOrThrow(ADDRESS)));
msgList.add(sendMsg);
cur.moveToNext();
}
// do{
// sendMsg.setId(cur.getString(cur.getColumnIndexOrThrow(_ID)));
// sendMsg.setDownSize(cur.getString(cur.getColumnIndexOrThrow(DOWN_SIZE)));
// sendMsg.setTimeLong(cur.getString(cur.getColumnIndexOrThrow(TIME_LONG)));
// sendMsg.setAddress(cur.getString(cur.getColumnIndexOrThrow(ADDRESS)));
// msgList.add(sendMsg);
// }while(cur.moveToNext());
}
close();
}catch(Exception e){
}
return msgList;
}
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.emlSendToFriendSubject));
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto});
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.emlSendToFriendBody));
File file = getFileStreamPath(EMAIL_TEMP_FILE);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
startActivityForResult(Intent.createChooser(emailIntent, getResources().getString(R.string.btnSendToFriend)),ActMain.EMAIL_DONE);
2.
<ImageView xmlns:android="http://schemas.android.com/apk/res/android">
android:id='@+id/splash_medium'
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="/blog_article/@drawable/wallpaper320x480/index.html"
/>
我在ImageView 中有个图片是320*480 和整个屏幕的大小一样
可是竟然不能填满整个屏幕 那么需要设置android:scaleType="fitXY",这是因为可能我们的像素不够,没有告知系统怎么伸展这个图片。
不过要注意android:scaleType="fitXY",是要和 android:src一起使用的 而不是和android:background。
因为android:background默认已经知道了是fitXY。
有时候上面两个属性我们都需要,这是因为我们需要给图片加一个相框,那么这个相框呢我们使用android:background
而我们的图片可以使用android:src。