我正在编写ListAdapter的自定义实现.
在它的构造函数中,我接受一个Context,一个资源ID(即代表布局文件的R.id.xxx),一个列表和一个map(这些包含数据).
现在,问题是我需要一个LayoutInflater来获取View对象,该对象位于单独的布局XML文件中.
如果只给出Context,我怎样才能获得LayoutInflater?
现在,为什么我认为这是可能的,这与传递给ArrayAdapter的构造函数(context,resource,textViewResourceId,data array)非常相似,我认为ArrayAdapter也必须使用LayoutInflater只给出了一个Context.
但怎么办呢?
我对Java非常熟悉,在C中则不是这样.
在Java中,如果我有一个方法可以做某事并返回一个String,它看起来像:
private String doSomething(...) {
String s;
// do something;
return s;
}
Run Code Online (Sandbox Code Playgroud)
C中的句法等价物不起作用,是完全错误的:
char* doSomething(...) {
char s[100];
// do something;
return s;
}
Run Code Online (Sandbox Code Playgroud)
当然我能做到:
char* doSomething(...) {
char *s;
s = malloc(100 * sizeof(char));
// do something;
return s;
}
Run Code Online (Sandbox Code Playgroud)
这会工作(我想!)但我很少看到代码这样做(是因为它不必要地填充堆?)
最常见的是,我看到:
bool doSomething(char *s) {
// do something that copies chars to s
return true;
}
Run Code Online (Sandbox Code Playgroud)
调用语句将是:
char s[100];
doSomething(s);
Run Code Online (Sandbox Code Playgroud)
如果在函数本身内部之前我不知道char数组的大小怎么办?即我无法在函数外声明char数组,然后将其传入.
处理这种情况的正确方法是什么?
比方说,我有一个URI http://127.0.0.1/somecontroller/someaction#12345
,带我到someAction()
someController控制器的动作.从那里,我能够通过检索Request对象$this->getRequest()
.
我还能够从Request对象中检索有关URI的各种信息.
但是,我如何检索片段(即例如#之后的"12345"部分)?既没有getRequestUri()
也没getParams()
出现片段部分.
谢谢!
我想在我的视图中显示模态进度"轮"叠加.
ProgressDialog接近,但我不想要对话框背景或边框.
我尝试设置对话框窗口的背景drawable:
this.progressDialog = new ProgressDialog(Main.this);
this.progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.progressDialog.setCancelable(false);
this.progressDialog.setIndeterminate(true);
this.progressDialog.show();
Run Code Online (Sandbox Code Playgroud)
但无济于事(即看起来仍然没有... setBackgroundDrawable代码).
我写了一个Python脚本来通过IMAP访问,管理和过滤我的电子邮件(使用Python的imaplib).
要获取电子邮件的附件列表(不先下载整个电子邮件),我使用电子邮件的UID获取电子邮件的bodystructure,即:
imap4.uid('FETCH', emailUID, '(BODYSTRUCTURE)')
Run Code Online (Sandbox Code Playgroud)
并从那里检索附件名称.
通常,包含附件名称的"部分"看起来像:
("attachment" ("filename" "This is the first attachment.zip"))
Run Code Online (Sandbox Code Playgroud)
但有几次,我遇到了类似的事情:
("attachment" ("filename" {34}', 'This is the second attachment.docx'))
Run Code Online (Sandbox Code Playgroud)
我读到某个地方,有时候,IMAP会使用带有字符串长度的大括号,后跟实际字符串(不带引号),而不是用双引号括起来表示字符串.
例如
{16}This is a string
Run Code Online (Sandbox Code Playgroud)
但上面的字符串似乎并没有严格遵守(在结束的大括号后面有一个单引号,一个逗号和一个空格,字符串本身用单引号括起来).
当我下载整个电子邮件时,包含该附件的邮件部分的标题似乎正常:
Content-Type: application/docx
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="This is the second attachment.docx"
Run Code Online (Sandbox Code Playgroud)
我如何解释(呃...解析)"异常"的身体结构,理解额外的单引号,逗号等...
那是"标准"吗?
我的Android应用程序可以分为客户端UI层和API层.我想将它们部署为单独的"应用程序",以便可以重用API层.
在Eclipse中,我将它们编写为2个独立的Android项目.在客户端UI项目中,我在其构建路径(Project - > Properies - > Java Build Path - > Projects)中声明API项目.
通过Eclipse(在我的实际G1手机上)部署客户端UI项目时,它会自动部署API项目(打包到APK中).
但是,启动客户端UI应用程序时,我遇到此错误:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.VerifyError: myapp.android.testuiclient.Main
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1472)
at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.access$2100(ActivityThread.java:116)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4203)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
环顾四周,似乎我应该在UI客户端的清单文件中声明应用程序下的uses-library.
问题是,我应该在android:name下使用库?开发指南说"图书馆的名称",但图书馆的名称是什么?(我的意思是,在我的API"应用程序"中,我没有在任何地方声明任何库名.)
关于Zend Framework 1.9基础知识的一些问题.
我按照快速入门指南,基本上,自举涉及,
一个.来自index.php:
$ZEND_FRAMEWORK_LIB_PATH = '/appl/ZendFramework-1.9.7/library';
defined('APPLICATION_PATH') || define('APPLICATION_PATH', (realpath(dirname(__FILE__) . '/../application')));
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
set_include_path(implode(PATH_SEPARATOR, array((dirname(dirname(__FILE__)) . '/library'), $ZEND_FRAMEWORK_LIB_PATH, get_include_path(),)));
require_once 'Zend/Application.php';
$application = new Zend_Application(APPLICATION_ENV, (APPLICATION_PATH . '/configs/application.ini'));
$application->bootstrap()->run();
Run Code Online (Sandbox Code Playgroud)
湾 然后在Bootstrap.php中,我有
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array("namespace" => "Default_", "basePath" => dirname(__FILE__),));
return $autoloader;
}
protected function _initDoctype()
{
$this->bootstrap("view");
$view = $this->getResource("view");
$view->doctype("XHTML1_STRICT");
}
Run Code Online (Sandbox Code Playgroud)首先,我不明白的一些事情:
一个.如果用户不是通过默认的index.php访问该站点,这是否意味着引导(实际上,index.php中的所有代码,包括环境设置等,都将被绕过?)
湾 没有明确调用Bootstrap _initAutoload()
或_initDoctype()
方法的地方.那么这些方法何时被隐式调用?
C.因为在index.php中,我已经将配置文件"传入" '/configs/application.ini'
了Zend_Application构造函数,有没有办法在别处检索配置条目?
在我的应用程序中,我必须使用不同的数据库(所以我不能只使用resources.db.*
).所以在同一个application.ini文件中,我有,例如 …
我有一个包含UTF-16字符的文件.我在文件中读取并可以将字符存储在uint16_t数组或char数组中(更好的选择?)
但是我如何打印这些角色?
我正在尝试打印出一串 UTF-16 字符。我不久前发布了这个问题,给出的建议是使用 iconv 转换为 UTF-32 并将其打印为 wchar_t 字符串。
我做了一些研究,并设法编写了以下代码:
// *c is the pointer to the characters (UTF-16) i'm trying to print
// sz is the size in bytes of the input i'm trying to print
iconv_t icv;
char in_buf[sz];
char* in;
size_t in_sz;
char out_buf[sz * 2];
char* out;
size_t out_sz;
icv = iconv_open("UTF-32", "UTF-16");
memcpy(in_buf, c, sz);
in = in_buf;
in_sz = sz;
out = out_buf;
out_sz = sz * 2;
size_t ret = iconv(icv, &in, &in_sz, …
Run Code Online (Sandbox Code Playgroud) 要添加REG_MULTI_SZ多行注册表值,我可以这样做
reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0def\0"
Run Code Online (Sandbox Code Playgroud)
这将添加("abc","def").
但是如果我需要添加("abc","","def"),即两者之间的空项呢?
干
reg.exe ADD "HKLM\path\to\registry\key" /v RegistryValue /t REG_MULTI_SZ /d "abc\0\0def\0"
Run Code Online (Sandbox Code Playgroud)
给我一个"无效参数"错误.
这就是我想要实现的目标:
在TabWidget中使用TextView(即调用TabHost.TabSpec.setIndicator(View)
而不是TabHost.TabSpec.setIndicator(String)
).
我想用XML配置TextView而不是以编程方式构建它.
所以最初,在我的布局XML中,我有:
<TabHost
android:id="@+id/mainTabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="30px"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="30px">
</FrameLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
现在我想在某处放置TextView配置.它实际上并不"嵌套"在布局层次结构中的任何位置.但是,由于布局XML当然必须是有效的XML,因此它不能有多个根元素.所以我被迫在某处嵌套TextView.因此我只把它放在根目录下一层(TabHost):
<TabHost
android:id="@+id/mainTabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="30px"/>
<TextView
android:id="@+id/tvTabIndicatorPreferences"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/tab_name_preferences"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="30px">
</FrameLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我做:
final TabHost mainTabHost = (TabHost) this.findViewById(R.id.mainTabHost);
mainTabHost.setup();
final TextView tvTabIndicatorPreferences = (TextView) this.findViewById(R.id.tvTabIndicatorPreferences);
final TabHost.TabSpec tabSpecPreferences = mainTabHost.newTabSpec("tabPreferences");
tabSpecPreferences.setIndicator(tvTabIndicatorPreferences);
tabSpecPreferences.setContent(R.id.scrlTblPreferences);
mainTabHost.addTab(tabSpecPreferences);
Run Code Online (Sandbox Code Playgroud)
但这里有一个问题.当我尝试运行应用程序时,我得到一个例外
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Firefox 28.0调试Firefox扩展。
我已经按照https://developer.mozilla.org/zh-CN/Add-ons/Setting_up_extension_development_environment中的建议设置了开发环境(实际上,我只是采用了懒惰的方式,并安装了DevPrefs扩展来设置所有必要的信息:配置)
然后,我打开Firefox并进入调试环境(“工具”>“ Web开发器”>“浏览器工具箱”)。
然后,我转到“调试器”选项卡。
但是,在“源”窗格的扩展名(例如chrome:// myextension)下,我仅看到扩展名XPI中包含的一些JS和XUL文件。
如何在调试器中手动“加载文件”,以便设置断点并跟踪扩展的运行时?