Tag: android

Android:如何将ExecuteScalar移植到Java?

SqlCommand.ExecuteScalar方法 执行查询,并返回查询返回的结果集中第一行的第一列。 其他列或行将被忽略。 我想这将涉及大量使用generics。 假设我有一个SQLiteDatabase / Cursor对象。

为什么Xamarin等效的EditText.getText()返回一个字符串?

我是一个新的Xamarin.Android开发人员。 我最近阅读了一些在派生类中使用EditText方法的Java代码。 其中一个派生类’方法看起来像这样: private void checkMatchingBracket(int paramInt) { getText().removeSpan(this.openBracketSpan); getText().removeSpan(this.closeBracketSpan); … } 这让我感到困惑,因为我认为getText()返回了一个String ,因为EditText.Text属性是此类’Xamarin对应物中的string 。 然而,这种情况并非如此; 似乎getText()返回一个Editable ,它看起来像一个可变的字符串类型,它提供了额外的function,例如将“spans”附加到某些文本区域( SpannableString ?)。 我的猜测是Xamarin返回的string已从此Editable的文本中复制过来,因此我无法真正修改原始的Editable并使用其API。 我对么? 因为我正在使用Xamarin,是否无法访问原始的Editable ? 编辑:我想要做的具体事情是EditText本的颜色区域。 我发现这个答案使用跨度来实现这个目的: TextView textView = (TextView)findViewById(R.id.mytextview01); Spannable WordtoSpan = new SpannableString(“partial colored text”); WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(WordtoSpan); 但是,Xamarin的API EditText.Text.set只接受一个.NET string ,它显然没有颜色或“跨度”的概念。

如何使用visual studio和xamarin关闭活动android

我在我的项目上有登录,注册和主页。 我使用StartActivity(typeof(Register)); 打开注册页面。 当用户已插入数据并单击注册按钮时,我使用StartActivity(typeof(MainActivity)); 再次返回登录页面。 当我点击手机上的后退按钮时,它返回注册页面>登录页面>然后退出。 我想在打开新页面后关闭已创建的活动。 我的第二个问题,我有退出按钮,如何使用退出按钮关闭我的应用程序? 我正在使用Visual Studio 2015和Xamarin开发Android应用程序。

如何在Android上使用Unity显示触摸屏键盘时调整视图大小?

在Unity中,我无法控制触摸屏键盘。 TouchScreenKeyboard类只有一个Android参数。 if(TouchScreenKeyboard.visible) { float keyboardHeight = TouchScreenKeyboard.area.height; // will resize the view here! But this return zero! } 有没有其他方法可以知道Android上键盘的高度?

发现Xamarin.Android中的蓝牙设备列表

在多个论坛和网站告诉我们如何发现蓝牙设备(配对或未配对)之后,我写下了这段代码。 class MainActivity: Activity { BluetoothAdapter btAdapter; static ArrayAdapter newDevicesArrayAdapter; public static List mDeviceList = new List(); DeviceDiscoveredReceiver receiver; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); receiver = new DeviceDiscoveredReceiver(this); IntentFilter filter = new IntentFilter(BluetoothDevice.ActionFound); RegisterReceiver(receiver, filter); btAdapter = BluetoothAdapter.DefaultAdapter; } class DeviceDiscoveredReceiver : BroadcastReceiver { Activity mainActivity; public DeviceDiscoveredReceiver(Activity activity) { this.mainActivity = activity; […]

在屏幕点读取像素颜色(有效)

我需要在屏幕上读取C#Unity3D中的像素颜色。 我正在使用Render Texture和ReadPixels方法。 每0.5秒使用它对性能有害(即使我的渲染纹理大小为128x128px),我正试图找到另一种方法来更快地获得这些数据。 我在某处读到可以直接使用glReadPixels但我不知道如何使用它? 我需要检测在这个地方(屏幕上的点)是否是某种东西。 这是我目前的代码。 using UnityEngine; using System; using System.Collections; public class ColController : MonoBehaviour { public Camera collCamera; public Texture2D tex2d; void Start() { collCamera = GetComponent(); tex2d = new Texture2D(collCamera.targetTexture.width, collCamera.targetTexture.height, TextureFormat.ARGB32, false); RenderTexture.active = collCamera.targetTexture; StartCoroutine (Execute ()); } IEnumerator Execute() { while (true) { yield return new WaitForEndOfFrame […]

WCF Rest服务接收对象为null

我有WCFrest服务,期望对象作为输入。 [WebInvoke(Method = “POST”, UriTemplate = “SaveItem”, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] [OperationContract] public string SaveItem(Item item) { string retValue; using (var business = new ItemBusiness()) { retValue = business.SaveItem(item).ToString(); } return retValue; } 项目类如下所示。 [DataContract] public class Item { [DataMember] public string UserId { get; set; } [DataMember] public string […]

如何在MonoDroid中制作动画监听器?

我想把这个Android代码转换为monoDroid Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2); fade2.setAnimationListener(new AnimationListener() { public void onAnimationEnd(Animation animation) { startActivity(new Intent(QuizSplashActivity.this, QuizMenuActivity.class)); QuizSplashActivity.this.finish(); } }); 到目前为止我有这个 Animation fade2 = AnimationUtils.LoadAnimation(this, Resource.Animation.Fade_in2); fade2.SetAnimationListener(????); 我没有看到新的AnimationListener()。 它似乎不需要一些界面或东西。

垂直翻转字节数组中位图的算法

我正在通过Mono For Android为Android中的便携式蓝牙打印机编写一个用于打印位图的课程。 我的类用于从流中获取像素数据,以便可以以正确的格式将其发送到打印机。 现在这个类很简单,它只读取每个像素的高度,宽度和位数。 使用它读取的偏移量并将像素数据返回给打印机。 现在我只使用每像素1位黑白图像。 我正在使用的位图是Windows格式。 这是原始图像: 这是打印的结果,第一张图片没有任何变换。 第二个是使用以下代码修改BitArray的结果: BitArray bits = new BitArray(returnBytes); BitArray flippedBits = new BitArray(bits); for (int i = 0, j = bits.Length – 1; i < bits.Length; i++, j–) { flippedBits[i] = bits[j]; } 我的问题是: 当我使用字节数组时,如何垂直翻转图像。 我无法找到执行此操作的算法,所有示例似乎都建议使用我无法使用的已建立的图形库。 编辑: 我的位图保存在一维数组中,第一行是字节,第二行是第三,等等。

如何在我的可视化C#web服务中为我的Android应用程序调用LINQ中的用户定义函数?

我目前正在开发一个应用程序,它将根据距离检索其他用户的位置。 我有一个数据库,以纬度和经度存储所有用户位置信息。 由于这两对纬度和经度之间的距离计算非常复杂,我需要一个函数来处理它。 from a in db.Location.Where(a => (calDistance(lat, longi, Double.Parse(a.latitude), Double.Parse(a.longitude)))<Math.Abs(distance) )) {…} 但是,我收到以下错误:LINQ to Entities无法识别该方法,并且此方法无法转换为商店表达式。 我不知道如何将它翻译成商店表达式,而且,计算也需要数学库。 是否有任何方法可以让LINQ表达式调用我自己的函数? 也许有其他方法可以实现我的目标,任何人都可以帮忙吗?