cursor

iOS: Programmatically move cursor up, down, left and right in UITextView

风格不统一 提交于 2019-12-01 08:01:19
I use the following code to move the cursor position to 5 characters from the beginning of a UITextField : txtView.selectedRange = NSMakeRange(5, 0); Now, if I have a cursor at an arbitrary position as shown in the image below, how can I move the cursor up, down, left and right? Left and right should be more or less easy. I guess the tricky part is top and bottom. I would try the following. You can use caretRect method to find the current "frame" of the cursor: if let cursorPosition = answerTextView.selectedTextRange?.start { let caretPositionRect = answerTextView.caretRect(for: cursorPosition

Android 数据存储之ContentProvider 使用和应用场景

随声附和 提交于 2019-12-01 07:48:31
备注:   ContentProvider1进程一代码: https://github.com/zengyuan/ContentProvider1Mode   ContentProvider1进程二代码: https://github.com/zengyuan/ContentProvider2Mode 注意,最主要是provider的配置,以及URl的provider地址要相同; 一,ContentProvider 主要用于不同的应用程序之间实现数据共享功能! 主要分为6个:   1.使用SQLite技术,创建好数据库和数据表;   2.新建类继承ContentProvider,重写6个抽象方法(通过这六个方法对数据库进行操作);   3.在Manifest中注册provider;   4.创建UriMatcher,定义Uri规则,添加注册数据库链表的名称;   5.ContentResolver对ContentProvider中共享的数据进行增删改查操作;   6.获取数据并修改等(进程一进程二增删改查方式一样); 二,进程一代码伺候:     第一步创建数据库(sql语句直接执行的): package com.saiyi.contentproviderdemo1; import android.content.Context; import android.database

Generating a sequence in sql server

醉酒当歌 提交于 2019-12-01 07:38:07
I am working on a function that will take a low number and a high number as paramaters and returns a table containing everything between (and including). I know I could use a cursor and increment a variable adding it to a scope based table every iteration, but I would prefer to avoid a cursor if possible. Does anyone else have a suggestion for a way to do this? (As i'm typing this im thinking possibly a CTE, which I will go investigate). Martin Smith Just create an indexed permanent auxiliary numbers table and be done with it. This will out perform any other method. See Jeff Moden's answer

Restore cursor position after .replace()

♀尐吖头ヾ 提交于 2019-12-01 07:28:23
问题 My biggest problem is that after it's replaced, the cursor defaults to the end of the textarea. That's no issue if I'm typing, but if I'm going back and editing, it's really annoying. Here's what I tried (the id of the textarea is "area") var el = e.area; position = el.selectionStart; // Capture initial position el.value = el.value.replace('\u0418\u0410', '\u042F'); el.selectionEnd = position; // Set the cursor back to the initial position. 回答1: You can try the following code snippet. In its

How to change cursor when dropping into Java application

早过忘川 提交于 2019-12-01 07:01:20
问题 I'm having some problems I just can't figure out... I'm writing a Swing Java application with a JList that accepts drag-and-drops. I want to change the cursor while dragging a file or folder from my system over the Java application. 回答1: I've found it myself... Thanks Clinton for answering though. Here's what I've used: first create the JList... You all know how to do that... Then I've added a setDropTarget: lstFiles.setDropTarget(new DropTarget() { @Override public synchronized void drop

Using SimpleCursorAdapter with Spinner?

房东的猫 提交于 2019-12-01 06:55:23
I have a db with table "mytable" having 2 colums "id","sampletext" I want to query distinct values of sampletext and feed to a Spinner using SimpleCursorAdapter. here is what is tried String[] cols=new String[]{"sampletext"}; int[] lbls=new lbls[]{android.R.id.text1}; mycursor=sdb.query(true,"mytable", cols,null,null,null,null,null,null); sca=new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, mycursor, cols,lbls,0); sca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spn.setAdapter(sca); When i run this i get error at line 4 : id does not exist. when i

Android - how to delete item from a cursor?

冷暖自知 提交于 2019-12-01 06:47:25
问题 Let's say I make the following cursor to get the call log of someone: String[] strFields = { android.provider.CallLog.Calls.NUMBER, android.provider.CallLog.Calls.TYPE, android.provider.CallLog.Calls.CACHED_NAME, android.provider.CallLog.Calls.CACHED_NUMBER_TYPE }; String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Cursor mCallCursor = getContentResolver().query( android.provider.CallLog.Calls.CONTENT_URI, strFields, null, null, strOrder ); Now how would I go about deleted the

java.lang.IllegalStateException: attempt to re-open an already-closed object

霸气de小男生 提交于 2019-12-01 06:34:52
问题 I'm trying to figure out why occasionally I'm getting the IllegalStateException. I can't find any good examples that show how to load a list using a thread to query a SQLite database. I've included my code below. Most of the time it works correctly, but occasionally, I'm getting the IllegalStateException. I have also gotten a similar exception in another activity of mine that is an instance of ExpandableListActivity. That exception states "trying to requery an already closed cursor". Can

Sort DB data and display in list view

两盒软妹~` 提交于 2019-12-01 06:33:33
I get data from my DB using cursor = db.query("WebLeadMaster", select, "condition1="+conditionVal1+ " and condition2="+ConditionVal2,null, null, null, "RegistrationTime DESC"); I am getting the data in my cursor alright. To display the data, i use the following code: SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.resultleadlookup, cursor, columns, to); mAdapter.notifyDataSetChanged(); lstResult.setAdapter(mAdapter); So, I cannot modify the contents of the cursor. The sort query has condition "RegistrationTime" which is a String data type. As you can see in the image

Get images thumbnail file paths

南楼画角 提交于 2019-12-01 06:31:08
I'm trying to get the thumnail paths , not the bitmaps objects. When I query for these, some of the thumbnail paths are null for some reason. (I have 1028 thumbnail images in my device, the cursor length is indeed 1028, but still returning nulls) I know there are 1028 thumbnail images because I checked. Here's my code: String[] projection = {MediaStore.Images.Thumbnails._ID}; // Create the cursor pointing to the SDCard cursor = this.getContentResolver().query( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, // Which columns to return null, // Return all rows null, MediaStore