假设我有一个以编程方式添加了片段的活动:
private void animateToFragment(Fragment newFragment, String tag) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, newFragment, tag);
ft.addToBackStack(null);
ft.commit();
}
Run Code Online (Sandbox Code Playgroud)
返回到可见的上一个片段的最佳方法是什么?
我在Android按钮点击时发现了Trigger后退按钮功能,但我认为模拟后退键事件不是正确的方法(我也无法让它工作):
dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
Run Code Online (Sandbox Code Playgroud)
打电话finish()
只关闭我不感兴趣的活动.
有没有更好的方法来解决这个问题?
我尝试过使用以下两个source-reference-lines.他们都编译.但有什么区别?
第一种方法:
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
第二种方法:
<link href="~/Scripts/jquery-1.4.1.js" type="text/javascript" />
Run Code Online (Sandbox Code Playgroud)
注:另外还有一个类似的区别script
和link as="script"
标签,询问有关<link href="js/script.js" as="script">
,这是不同的.
我有一个活动,我动态地替换片段:
private void goToFragment(Fragment newFragment, String tag) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, newFragment, tag);
ft.addToBackStack(null);
ft.commit();
}
Run Code Online (Sandbox Code Playgroud)
现在,我想访问片段内的视图,这样我就可以在调用后立即将数据(我已存储在我的活动中)放入其中goToFragment
.
问题是,在onCreateView
完全呈现片段之前不会调用片段,至少根据我的理解.
我知道覆盖onAttach(Activity activity)
片段是一种方法,但我必须将它专门用于我的活动 - 我只是想避免这种情况,因为我认为片段依赖于特定活动是不好的做法.
据我所知,Fragment
没有任何听众(作为主题)实施.
所以我想我必须创建自己的监听器(使用Observer模式使片段成为主题,活动成为观察者),然后在完成onCreateView
或调用时调用它onAttach
,然后最终使用数据调用片段需要设定.但是,我需要为几个片段执行此操作,因此我必须为每个片段创建一个侦听器,我再次认为这是不好的.
有没有更好/更简单的方法来做到这一点?
MSDN声明以下语法:
RAISERROR ( { msg_id | msg_str | @local_variable }
{ ,severity ,state }
[ ,argument [ ,...n ] ] )
[ WITH option [ ,...n ] ]
Run Code Online (Sandbox Code Playgroud)
在msg_str
预计一个字符串,最多2047个字符,但截断长字符串.它还可以替换参数,这会截断消息,而不是值提供的字符数:
错误消息最多可包含2,047个字符.如果消息包含2,048个或更多字符,则仅显示前2,044个字符,并添加省略号以指示消息已被截断.请注意,由于内部存储行为,替换参数消耗的字符数多于输出显示的字符数.例如,%d的替换参数(指定值为2)实际上会在消息字符串中生成一个字符,但内部还会占用另外三个存储字符.此存储要求会减少消息输出的可用字符数.指定msg_str时,RAISERROR会引发错误消息,错误编号为50000.
在severity
预计25 0之间的数字,但更正其他号码:
任何用户都可以指定从0到18的严重级别.从19到25的严重级别只能由sysadmin固定服务器角色的成员或具有ALTER TRACE权限的用户指定.对于从19到25的严重性级别,需要WITH LOG选项.严重级别小于0将被解释为0.严重级别大于25将被解释为25.
的state
预计值0到255,但校正零度以下的值:
[state]是0到255之间的整数.负值默认为1.不应使用大于255的值.
运行这些查询时出现以下错误:
RAISEERROR('Test', 20, 1);
Run Code Online (Sandbox Code Playgroud)
Msg 102,Level 15,State 1,Line 1
'Test'附近的语法不正确.
DECLARE @err_message nvarchar(255);
SET @err_message = 'Test';
RAISEERROR(@err_message, 20, 1);
Run Code Online (Sandbox Code Playgroud)
Msg 102,Level 15,State 1,Line 3
'RAISEERROR'附近的语法不正确.
我可以很好地执行各种其他查询.例如:
THROW 50001, 'Test', 1;
Run Code Online (Sandbox Code Playgroud)
Msg 50001,Level 16,State 1,Line …
这段代码正在创建BufferedReader和InputStreamReader导致的内存泄漏问题,我认为可能会发生一些异常.我该怎么改变它?
try{
URL url = new URL(sMyUrl);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((str = in.readLine()) != null) {
jsonString += str;
}
in.close();
}catch(Exception e){
}
Run Code Online (Sandbox Code Playgroud) 我是Entity Framework的新手,并且设置了正确的SQL Server.
我正在遵循正式的实体框架教程,而我正在"创建数据库" - 页面下约30%.
将School.mdf文件从以下文件夹复制到应用程序的App_Data文件夹
而不是使用School.mdf
我正在使用我自己的文件的文件,该文件是使用SQL Server Management Studio(我从Microsoft下载中心下载,选择ENU\x86\SQLEXPRADV_x86_ENU.exe
选项)自动创建的,以创建包含表的数据库.
在Visual Studio 2010 Ultimate中,我:
转到Server Explorer
并右键单击Data Connections
- > Add Connection
:
选择Microsoft SQL Server Database File
数据源的选项,然后按Continue
.
点击Browse...
下面Database file name
.
选择目录中的%PROGRAMFILES%\Microsoft SQL Server\MSSQL11.MOBILIZEMESQL\MSSQL\DATA
文件,因为它是保存的位置.
得到错误.
图片版本:
1.
2.
3.
我收到错误消息:
DateBaseName.mdf
This file is in use.
Enter a new name or close the file that's …
Run Code Online (Sandbox Code Playgroud) sql-server entity-framework database-connection visual-studio-2010 sql-server-2012-express
这个程序实际上如何工作......?
import java.util.Scanner;
class string
{
public static void main(String a[]){
int a;
String s;
Scanner scan = new Scanner(System.in);
System.out.println("enter a no");
a = scan.nextInt();
System.out.println("no is ="+a);
System.out.println("enter a string");
s = scan.nextLine();
System.out.println("string is="+s);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
enter the no
1234
no is 1234
enter a string
string is= //why is it not allowing me to enter a string here?
Run Code Online (Sandbox Code Playgroud) 该IDbCommandInterceptor
接口是不是非常有据可查.我只发现了一些稀缺的教程:
还有一些问题:
这些是关于挂钩的建议我发现:
1 - 静态DbInterception
类:
DbInterception.Add(new MyCommandInterceptor());
Run Code Online (Sandbox Code Playgroud)
2 - 在DbConfiguration
课堂上做上述建议
public class MyDBConfiguration : DbConfiguration {
public MyDBConfiguration() {
DbInterception.Add(new MyCommandInterceptor());
}
}
Run Code Online (Sandbox Code Playgroud)
3 - 使用配置文件:
<entityFramework>
<interceptors>
<interceptor type="EFInterceptDemo.MyCommandInterceptor, EFInterceptDemo"/>
</interceptors>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)
虽然我无法弄清楚如何将DbConfiguration
类挂钩到DbContext,并且既没有放入type
config方法的部分.我发现的另一个例子似乎建议您编写记录器的命名空间:
type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework"
Run Code Online (Sandbox Code Playgroud)
我注意到了DataBaseLogger
工具IDisposable
,IDbConfigurationInterceptor
和
IDbInterceptor
.IDbCommandInterceptor
也实现了IDbInterceptor
,所以我尝试(没有成功)格式化它像这样:
type="DataLayer.Logging.MyCommandInterceptor, DataLayer"
Run Code Online (Sandbox Code Playgroud)
当我DbInterception
直接调用静态类时,它每次调用都会添加另一个拦截器.所以我的快速而肮脏的解决方案是利用静态构造函数:
//This partial class is …
Run Code Online (Sandbox Code Playgroud) 我正在尝试GET
使用客户端证书向外部生产服务器发出简单请求.他们已将我们的证书添加到他们的服务器,我已成功通过Postman(Chrome应用程序和Windows本机应用程序)和标准浏览器发出请求:
Postman的Chrome应用版本使用Chrome内置的证书查找器.本机Postman应用程序需要一个.crt和.key文件,我从.p12文件中提取.
换句话说,证书在商店中成功找到,并且在从文件中使用时也可以工作(在Windows本机应用程序中,表明它应该可以在.NET中使用).
在我的简单C#(.NET Framework 4.5.1)控制台应用程序中,我能够从商店(或从文件)获取证书,并成功使用它来加密和解密文件(我认为它具有完全访问权限)来自我的申请):
private static X509Certificate2 GetCertificate(string thumbprint)
{
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection coll =
store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint,
validOnly: true);
X509Certificate2 certificate = coll.Count == 0 ? null : coll[0];
return certificate;
}
Run Code Online (Sandbox Code Playgroud)
我提出请求到服务器使用两种HttpClient
或HttpWebRequest
:
//A global setting to enable TLS1.2 which is disabled in .NET 4.5.1 and 4.5.2 by default,
//and disable SSL3 which has been deprecated for a while. …
Run Code Online (Sandbox Code Playgroud) 想象一下这些规范来自外部 dll。显式实现接口的类:
public interface IDebug
{
string GetImportantInfo();
}
public class ExternalClass : IDebug
{
public void DoSomethingImportant()
{
System.Diagnostics.Debug.WriteLine("Something important was done...");
}
string IDebug.GetImportantInfo() //Explicit implementation
{
DoSomethingImportant();
return nameof(ExternalClass);
}
}
Run Code Online (Sandbox Code Playgroud)
然后这个来自内部代码,你知道你需要实现接口:
public class Debug : ExternalClass, IDebug
{
public string GetImportantInfo()
{
return nameof(Debug);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我从子类调用Debug
'sGetImportantInfo()
方法时,不会调用超类中的显式实现:
static void Main(string[] args)
{
IDebug test = new Debug();
var impInfo = test.GetImportantInfo();
System.Diagnostics.Debug.WriteLine(impInfo); //"Debug"
}
Run Code Online (Sandbox Code Playgroud)
我似乎得到的唯一轻微提示是,在将IDebug
接口添加到Debug
类时,没有实现该方法,我没有收到编译错误:
public class Debug …
Run Code Online (Sandbox Code Playgroud) c# ×3
android ×2
java ×2
sql-server ×2
back-stack ×1
interceptor ×1
interface ×1
javascript ×1
logging ×1
polymorphism ×1
raiserror ×1
sql ×1
ssl ×1
t-sql ×1
user-input ×1