我正在尝试使用此函数在Android中使用spannableString和正则表达式为部分字符串着色:
public static String StringReplace(String source) {
String find = "ABC";
SpannableString replace = new SpannableString(find);
replace.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
String output = source.replace(find, replace);
return output;
}
Run Code Online (Sandbox Code Playgroud)
因为函数replace()返回一个字符串,我无法获得彩色字符串.我的问题是:使用regexp为文本部分着色的最佳方法是什么?
有没有办法使用VBA将RTF文本从Access数据库中的备注字段复制到Word文档.我目前有这个代码,但它产生html文本(文本包含标签而不是格式化).
' Query the database and get the sales for the specified customer
Set rs = CurrentDb.OpenRecordset("SELECT * FROM Sales WHERE Sales.[ID] ='" & Forms![customers]![id] & "'")
'Check to see if the recordset actually contains rows
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
' Create file and add rtf text
Set ts = fso.CreateTextFile("c:\temp\temp.rtf", True)
ts.Write rs(3)
ts.Close
' Add a row
doc.Tables(1).Rows.Add
' Get the number of the added row to add data
i …Run Code Online (Sandbox Code Playgroud) 我正在尝试将背景图像添加到我的应用程序中的listActivity.但是,使用我使用的代码时,背景图像显示在每一行而不是整个列表中.
这是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8px" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/qbg1"/>
<TextView
android:id="@+id/employeeID"
android:layout_width="50px"
android:layout_marginRight="20px"
android:layout_height="wrap_content"
android:textColor="@color/textColor"/>
<TextView
android:id="@+id/employeeName"
android:layout_width="wrap_content"
android:layout_marginRight="10px"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/employeeID"
android:textColor="@color/textColor"/>
</RelativeLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/qbg1"/>
Run Code Online (Sandbox Code Playgroud)
将背景图像添加到活动的最佳方法是什么?我更喜欢在XML文件中而不是以编程方式.
我试图在sqlite中使用正则表达式搜索数据库.这是我的代码:
cursor = db.rawQuery("SELECT _id, employee FROM employees WHERE employee REGEXP ?",
new String[]{"%" + prepareSearchText() + "%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.search_row,
cursor,
new String[] {"_id", "employee "},
new int[] {R.id.idField, R.id.nameField});
setListAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
但是我收到此错误:
Caused by: android.database.sqlite.SQLiteException: no such function: REGEXP.
Run Code Online (Sandbox Code Playgroud)
之前我在MySQL中使用了函数REGEXP,所以我认为它存在于sqlite中,但显然它不是.
在android中查询sqlite数据库时执行正则表达式的最佳方法是什么?
我试图通过使用以下代码覆盖onPause方法,在活动暂停之前显示一个Toast消息:
@Override
protected void onPause() {
Toast.makeText(this, "Paused", Toast.LENGTH_LONG);
super.onPause();
}
Run Code Online (Sandbox Code Playgroud)
根据此http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle 活动在返回此方法之前不会暂停:
"Implementations of this method must be very quick because the next activity will not be resumed until this method returns."
Run Code Online (Sandbox Code Playgroud)
但是根本不显示Toast消息.
我想在Android上使用OnItemLongClickListener作为listView.添加到onCreate方法时,此代码可以正常工作.
mContactList.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Log.e("MyApp", "get onItem Click position= " + position);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试实现OnItemLongClickListener接口并在类中使用此方法时:
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Log.e("MyApp", "get onItem Click position= " + position);
return false;
}
Run Code Online (Sandbox Code Playgroud)
什么都没发生.我错过了什么?