我需要在Activity启动时为ListPreference设置defult值.我已尝试过,ListPreference.setDefaultvalue("value");但它会将列表的第一个条目作为默认值.我需要它,因为我必须检查一个条件并设置为默认值满足该条件的值,所以我认为它不能从xml文件中完成(带android:defaultValue)
例如,假设我在arrays.xml中有这个值数组:
<string-array name="opts">
<item>red</item>
<item>green</item>
<item>blue</item>
</string-array>
<string-array name="opts_values">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
Run Code Online (Sandbox Code Playgroud)
在PreferenceScreen xml中:
<ListPreference
android:title="Colour select"
android:summary="Select your favourite"
android:key="colour"
android:entries="@array/opts"
android:entryValues="@array/opts_values" />
Run Code Online (Sandbox Code Playgroud)
在活动中,我想做这样的事情:
String mycolour;
if (something) {
mycolour="1";
} else {
mycolour="2";
}
ListPreference colour = (ListPreference) findPreference ("colour");
colour.setDefaultValue(mycolour);
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为它使第一选择成为默认选择.你能解释一下如何制作另一个默认的吗?谢谢.
我在使用Spring为JNDI设置配置时遇到问题.我检查了其他帖子,但无法解决我的问题.我使用Tomcat 6作为我的容器.根据我的理解,我需要在服务器上设置资源.所以在我的server.xml文件中我有这个:
<GlobalNamingResources>
<Resource auth="Container" driverClassName="org.postgresql.Driver"
maxActive="100" maxIdle="5" maxWait="10000"
minEvictableIdleTimeMillis="60000" name="jdbc/myTomcatPool"
password="password" testOnBorrow="true" testWhileIdle="true"
timeBetweenEvictionRunsMillis="10000" type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/postgis" username="postgres"
validationQuery="SELECT 1"/>
</GlobalNamingResources>
Run Code Online (Sandbox Code Playgroud)
我在我的spring-context.xml(在类路径上)有以下内容:
<jee:jndi-lookup id="geoCodeData" jndi-name="java:comp/env/jdbc/myTomcatPool" />
<bean id="geoCodeService" class="com.sample.SampleImpl">
<property name="dataSource" ref="geoCodeData"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
然后我在文件中有这个META-INF/context.xml:
<Context path="/myApp" reloadable="true" cacheMaxSize="51200"
cacheObjectMaxSize="2560">
<ResourceLink global="jdbc/myTomcatPool" name="jdbc/myTomcatPool"
type="javax.sql.DataSource"/>
</Context>
Run Code Online (Sandbox Code Playgroud)
我的服务器启动时没有错误.
当我尝试运行以下测试时(在我添加JNDI代码之前有效):
public class Test {
public static void main(String[] args) {
ApplicationContext ctx =
new ClassPathXmlApplicationContext("spring-context.xml");
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
线程"main"中的异常org.springframework.beans.factory.BeanCreationException:创建名为'geoCodeData'的bean时出错:init方法的调用失败;
嵌套异常是javax.naming.NoInitialContextException:需要在环境或系统属性或applet参数或应用程序资源文件中指定类名:java.naming.factory.initial
我的配置是错误的还是我尝试运行测试的方式不正确?
我有一个activity在其中有一个async task会做一些下载的东西.在下载时它会显示al oading dialog.
我的问题是,当我这样做时,它对我来说很好one orentiaon.但是当我rotate在下载时,它显示window leaked并将
dialog.cancel 在我的帖子中执行崩溃.
从我对它的研究中我理解它是因为change in the context设备何时出现rotated.
也就是说,当device是rotated该activity会recreated所以context会changed.
但我已经创建了与旧的对话框wasn't the current context.因此,当我取消它时显示错误
这是什么解决方案,任何想法frnds.
我使用honeycomb,我试过,fragment但没有得到一个很好的样本.我现在主要尝试这个,
如果有人可以给我一些链接,那将是伟大的
我试图在模拟器API 10(Android 2.3.3)中测试ForegroundDispatch(http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.html).
当我调用NfcAdapter.getDefaultAdapter(this)时,我得到null.为什么会这样?
码:
public class ForegroundDispatch extends Activity {
private NfcAdapter mAdapter;
private PendingIntent mPendingIntent;
private IntentFilter[] mFilters;
private String[][] mTechLists;
private TextView mText;
private int mCount = 0;
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.foreground_dispatch);
mText = (TextView) findViewById(R.id.text);
mText.setText("Scan a tag");
mAdapter = NfcAdapter.getDefaultAdapter(this);
// Create a generic PendingIntent that will be deliver to this activity. The NFC stack
// will fill in the intent with the details of the discovered tag before delivering to …Run Code Online (Sandbox Code Playgroud) 有没有办法让powershell出现在全屏?不仅可以在屏幕上最大化,还可以隐藏顶栏?
此外,由于这可能很难做到,如何根据当前分辨率最大化它?
尽管我喜欢django文档,但管理员中关于bookmarklet的部分却很奇怪.
我的问题是这样的:如果我在视图中并且我有一个django模型(或者,在某些情况下,是一个实际的对象),我怎样才能到达该模型(或对象)的相关管理页面?如果我有对象coconut_transportation.swallow.objects.all()[34],我怎么能直接跳到管理页面来编辑那个特定的燕子?
同样,如何获取管理页面的URL以添加另一个吞咽?
我正在转换PHP 5.3库以在PHP 5.2上工作.支持我的主要方法是使用后期静态绑定return new static($options);,如果我将其转换为return new self($options)将得到相同的结果?
new self和之间有什么区别new static?
我正在为我的应用程序构建一个管理控制台.
我补充道 admin_controller.rb ... class AdminController < ApplicationController
然后我加入resources :admin了我的路线.
然后我添加了一个空的模型,因为管理员视图没有DB表,它只是报告其他表:
class Admin < ActiveRecord::Base
end
Run Code Online (Sandbox Code Playgroud)
管理控制台在数据库中没有模型.
当我尝试访问/ admin视图时,我收到错误:
Access denied on index Admin(Table doesn't exist)
Run Code Online (Sandbox Code Playgroud) 我用的时候:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在控制台上我收到以下错误消息:
org.springframework的'dependencies.dependency.version':spring-context:jar必须是有效版本,但是'$ {spring.version}'.@第40行,第19栏
我是否必须手动配置Maven?我已经看到了这种依赖,但没有解释如何正确地做到这一点..提前
我有一个关于执行以下程序的问题.
#include<stdio.h>
int main(void)
{
char *p="hey friends",*p1;
p1=p;
while(*p!='\0')
{
p++;
printf("\n%p",p);
}
printf("%s %s",p,p1);
sleep(100);
}
Run Code Online (Sandbox Code Playgroud)
当我运行以下时,它输出如下输出:
0x8048521
0x8048522
0x8048523
0x8048524
0x8048525
0x8048526
0x8048527
0x8048528
0x8048529
0x804852a
Run Code Online (Sandbox Code Playgroud)
然后100秒后打印"0x804852b嘿朋友".虽然声明:printf("%s%s",p,p1); 在睡眠声明之前那么为什么它在睡觉之前不打印而且它再打印一个地址意味着它再次进入循环.有人可以解释一下上述程序的工作原理.它是否与printf函数的缓冲区有关?
android ×3
java ×3
spring ×2
c ×1
django ×1
django-admin ×1
django-urls ×1
fullscreen ×1
jndi ×1
maven ×1
nfc ×1
php ×1
powershell ×1
preference ×1
static ×1