我读过Android:将EditText限制为数字,如何在android中的EditText上显示数字键盘?.不幸的是,它们似乎都不符合我的需求.
我想将EditText输入限制为仅限数字.但是,我还想允许签名和/或十进制输入.
这是我当前的代码(我需要以编程方式执行此操作):
EditText edit = new EditText(this);
edit.setHorizontallyScrolling(true);
edit.setInputType(InputType.TYPE_CLASS_NUMBER);
Run Code Online (Sandbox Code Playgroud)
有了这个,我的EditText快乐地将所有输入限制为数字.不幸的是,它不允许任何其他内容,如小数点.
如果我将该行更改为edit.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL),则EditText接受所有输入(这不是我想要的...).
我尝试过组合旗帜(绝望地看看它是否会起作用):
edit.setInputType(InputType.TYPE_CLASS_NUMBER);
edit.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL)
edit.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED)
Run Code Online (Sandbox Code Playgroud)
这也不起作用(EditText照常接受所有输入).
那么,我该怎么做?
我正在尝试创建一个用于管理首选项的自定义布局.我知道有标准和推荐的布局PreferenceActivity,但如果我想添加,比方说,Button我怎么能得到它?
我计划设计应用程序,以便当用户触摸主活动屏幕上的某个项目时,它会转到用户可以启用的选项的"子菜单",随后会出现在下一个屏幕上(它必须在此线性进展).用户每次使用该应用程序时都必须设置这些.目前,我正在考虑使用该标准PreferenceActivity来表示这个选项的子菜单.
也许这不是正确的方法?
编辑:我在谷歌搜索时忽略了解决方案.如何向PreferenceScreen添加按钮
如果我插入重复的行,Android的SQLite库如何解决冲突?我正在为API级别7构建我的应用程序,遗憾的是,它没有SQLiteDatabase.insertOnConflict()从API级别8开始包含的方法.
我对CSS"层次结构"有一些问题(不确定将其称为层次结构是否合适).我正试图设计下面的HTML格式.
<body>
<section id="content">
<article>
<ul class="posts-list">
<li class="post-item">
<h2>[post title]</h2>
<p class="item-description">...</p>
<p class="item-meta">...</p>
</li>
...
</ul>
</article>
</section>
</body>
Run Code Online (Sandbox Code Playgroud)
由于部分#内容在我拥有的每个页面上都会发生变化,因此我希望在所有页面中保持一致的样式,因此我编写了一些"全局"CSS规则.
#content {
color: #000;
margin-left: 300px;
max-width: 620px;
padding: 0px 10px;
position: relative;
}
#content p,
#content li {
color: #111;
font: 16px / 24px serif;
}
Run Code Online (Sandbox Code Playgroud)
我想以ul.posts-list不同的方式设置HTML样式,所以我写了这些规则.
li.post-item > * {
margin: 0px;
}
.item-description {
color: #FFF;
}
.item-meta {
color: #666;
}
Run Code Online (Sandbox Code Playgroud)
但是,我遇到了一些问题.以下是Chrome渲染CSS的方式:

出于某种原因,规则#content p, #content li要重写我的规则.item-description和.item-meta.我的印象是,class/id名称被认为是特定的,因此具有更高的优先级.但是,似乎我对CSS的工作原理有误解.我在这做错了什么? …
我去年使用了操作系统,在此期间我使用用户上下文(在标题中定义ucontext.h)来实现项目的线程调度程序(其中每个线程模拟一个进程).我正在参加一个讲座,并将谈论用户上下文,我刚刚想到,尽管去年完成了这个项目,但我并不真正理解getcontext系统调用究竟是做什么的.
该getcontext状态的手册页"将ucp指向的结构初始化为当前活动的上下文".对于参数setcontext,它还指出"如果ucp参数是用getcontext()创建的,程序执行就会继续,好像刚刚返回了相应的getcontext()调用一样." 好的,我明白了.
所以这就是我所困惑的.通常,对于我学习它的方式,要执行上下文切换,可以初始化ucontext_t结构并交换/设置它:
ucontext_t ucp;
ucontext_t oucp;
getcontext(&ucp);
// Initialize the stack_t struct in the ucontext_t struct
ucp.uc_stack.ss_sp = malloc(STACK_SIZE);
ucp.uc_stack.ss_size = STACK_SIZE;
ucp.uc_stack.ss_flags = 0;
ucp.uc_link = /* some other context, or just NULL */;
// Don't block any signals in this context
sigemptyset(&ucp.uc_sigmask);
// Assume that fn is a function that takes 0 arguments and returns void
makecontext(&ucp, fn, 0);
// Perform the context switch. Function 'fn' …Run Code Online (Sandbox Code Playgroud) 我的database.yml设置如下:
development:
adapter: mysql2
encoding: utf8
database: devel
username: root
host: localhost
port: 3306
timeout: 5000
# ... snip ...
production:
adapter: mysql2
encoding: utf8
database: prod
username: <%= ENV["DB_USER"] %>
password: <%= ENV["DB_PASSWORD"] %>
host: <%= ENV["DB_HOST"] %>
port: 3306
timeout: 5000
Run Code Online (Sandbox Code Playgroud)
但问题是,尽管设置了环境变量,但Rails并未正确阅读这些变量.当我在EC2上启动我的Phusion支持的Nginx服务器时,我收到以下消息:
Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)
Run Code Online (Sandbox Code Playgroud)
我确认Phusion正在生产环境中启动Rails; 我将开发和测试配置中的用户名和主机更改为唯一名称,并'root'@'localhost'始终显示为错误消息.此外,如果我将用户名和密码硬编码到YAML文件中,服务器将正常启动.
我怀疑我没有正确设置我的环境变量,因为MySQL一直声称我试图以"root"身份登录而没有密码.我最初从.bashrc文件导出它们,但在阅读完这个问题后,我意识到这不是正确的方法.在搜索之后,我发现了这篇博文,所以我按照说明创建了这三个文件:
在/ usr/local/etc中/ ENV
export RAILS_ENV=production
export DB_PASSWORD= (snip)
export DB_USER=doorbells
Run Code Online (Sandbox Code Playgroud)
在/ usr/local/etc中/ ruby_wrapper
#!/bin/sh
source /usr/local/etc/env
exec /home/rooby/.rvm/wrappers/ruby-1.9.3-p362@doorbells-dev/ruby …Run Code Online (Sandbox Code Playgroud) 我需要在我的 Android 应用程序中连接到 Amazon 的 SimpleDB。Amazon Android SDK提供的示例项目将凭证放置在名为 AwsCredentials.properties 的文件中,该文件位于项目源代码中。然后源代码进行这些调用来访问和使用它们:
Properties properties = new Properties();
properties.load( getClass().getResourceAsStream( "AwsCredentials.properties" ) );
String accessKeyId = properties.getProperty( "accessKey" );
String secretKey = properties.getProperty( "secretKey" );
...
credentials = new BasicAWSCredentials( properties.getProperty( "accessKey" ), properties.getProperty( "secretKey" ) );
Run Code Online (Sandbox Code Playgroud)
这是正确且安全的方法吗?
我想实时显示TextView中的时间和日期(按分钟更新).目前,我有这个.考虑到内存使用和Android最佳实践,这是最好的方法吗?(注意:DateFormat是java.text.DateFormat)
private Thread dtThread;
public void onCreate(Bundle savedInstanceState) {
...
getDateAndTime();
}
private void getDateAndTime() {
dtThread = new Thread( new Runnable() {
@Override
public void run() {
Log.d(TAG, "D/T thread started");
while (!Thread.currentThread().isInterrupted()) {
try {
update();
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.d(TAG, "D/T thread interrupted");
}
}
}
public void update() {
runOnUiThread( new Runnable() {
@Override
public void run() {
Date d = new Date();
String time = DateFormat.getTimeInstance(DateFormat.MEDIUM).format(d);
String date = …Run Code Online (Sandbox Code Playgroud) 我正在动态生成TableRows.对于每个TableRow,在一列中有一个TextView,在另一列中有一个EditText.如何生成行,使TextView占据行的一半而EditText占用另一半?
这就是我目前拥有的:
布局xml文件
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:id="@+id/formTable" />
Run Code Online (Sandbox Code Playgroud)
Java源文件
private TreeMap<String, EditText> textData;
...
protected void onCreate(Bundle savedInstanceState) {
...
textData = populateMap();
...
TableLayout table = (TableLayout) findViewById(R.id.formTable);
configureTableLayout(table,textData);
}
private TreeMap<String, EditText> populateMap() {
TreeMap<String, EditText> map = new TreeMap<String, EditText>();
Set<String> dataTypeSet = app.getWorkingDataTypeList();
for (String dataTypeKey : dataTypeSet) {
EditText edit = new EditText(this);
edit.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
edit.setText("0");
edit.setHorizontallyScrolling(true);
map.put(dataTypeKey, edit);
}
return map;
}
private void configureTableLayout (TableLayout table,
Map<String, ? extends View> …Run Code Online (Sandbox Code Playgroud) 假设我有一个SQL数据库,其中列可能看起来像这样
Numbers
-------
1
1
2
3
4
4
Run Code Online (Sandbox Code Playgroud)
是否可以创建一个简单地抓取最大数字的单个SQL查询,在这种情况下会是4什么?或者我是否必须查询每个数字,将它们放在外部程序中的某种列表中,并编写算法以找到最大的数字?