小编Kal*_*mah的帖子

如何在android中使用带有Regex的SpannableString?

我正在尝试使用此函数在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为文本部分着色的最佳方法是什么?

java regex android

4
推荐指数
2
解决办法
5502
查看次数

使用VBA将Access中的RTF文本复制到word表

有没有办法使用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)

ms-access vba access-vba word-vba

4
推荐指数
1
解决办法
4216
查看次数

在Android中将背景图片添加到listview?

我正在尝试将背景图像添加到我的应用程序中的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文件中而不是以编程方式.

android android-layout

3
推荐指数
1
解决办法
1万
查看次数

如何在android中使用正则表达式搜索sqlite数据库?

我试图在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数据库时执行正则表达式的最佳方法是什么?

java sql sqlite android

3
推荐指数
1
解决办法
4658
查看次数

如何在android中的onPause()之前显示toast消息?

我试图通过使用以下代码覆盖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消息.

java android toast

2
推荐指数
1
解决办法
1390
查看次数

如何在Android中使用OnItemLongClickListener而不使用setOnItemLongClickListener?

我想在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)

什么都没发生.我错过了什么?

java android

1
推荐指数
1
解决办法
7123
查看次数

标签 统计

android ×5

java ×4

access-vba ×1

android-layout ×1

ms-access ×1

regex ×1

sql ×1

sqlite ×1

toast ×1

vba ×1

word-vba ×1