我需要在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)
但它不起作用,因为它使第一选择成为默认选择.你能解释一下如何制作另一个默认的吗?谢谢.
我应该通过Makefile编译一个用C编写的程序.我应该在Makefile中插入一些选项,例如:-O2, -march=i686.如何在不写入文件的情况下在Makefile中插入此选项?
我正在尝试开发一个Android应用程序,但我在GUI设计方面遇到了一些问题.屏幕截图的以下部分是我的问题(红色和蓝色线是由Android调试选项生成的).

这是代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/caption"
android:layout_below="@+id/caption" >
<ImageButton
android:id="@+id/button_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="@drawable/content_edit"
style="?android:attr/borderlessButtonStyle" />
<TextView
android:id="@+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/num_placeholder"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
如您所见,TextView myText与ImageButton button_edit重叠.一个简单的解决方案是使用LinearLayout而不是RelativeLayout.问题是:
我还尝试将myText的layout_width设置为'fill_parent',但它会填充编辑按钮左侧的整个屏幕的其余部分.
预期的行为是myText增加其高度(成为两行TextView)而不是重叠'button_edit'
谁能帮我?谢谢
我刚刚从Eclipse切换到Android Studio,我在使用ViewPagerIndicator的我的项目遇到了一些问题
这是Gradle代码:
repositories {
mavenCentral()
}
dependencies {
compile 'com.viewpagerindicator:library:2.4.1'
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:appcompat-v7:19.0.+'
}
Run Code Online (Sandbox Code Playgroud)
当我尝试构建项目时,Android Studio会返回此错误:
LoadViewPagerTask.java
Error:Error:line (30)error: package com.viewpagerindicator does not exist
Error:Error:line (82)error: cannot find symbol class TitlePageIndicator
Error:Error:line (82)error: cannot find symbol class TitlePageIndicator
Run Code Online (Sandbox Code Playgroud)
换句话说,该库未导入.有解决方案吗 感谢您的关注.
android gradle viewpagerindicator android-studio build.gradle
我正在构建一个Android应用程序,我需要从一个大小为33 MB的URL下载文件.
这里的下载任务:
try {
int MAX_BUFFER_SIZE = 4096;
URL mUrl = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
connection.setRequestMethod("GET");
long length = connection.getContentLength(), downloaded = 0;
int read;
byte [] buffer = new byte[(((int)length) > MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE : (int)length];
String filename = getFilename(mUrl);
File file = new File (SDCARD_ROOT);
if (!file.exists() || !file.isDirectory()){
file.mkdir();
}
this.filename = filename;
file = new File (SDCARD_ROOT + this.filename);
FileOutputStream fos = new FileOutputStream (file);
//Start downloading
InputStream stream = connection.getInputStream();
while …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的GSM Galaxy Nexus(maguro)编译一个deodexed aosp.我在谷歌搜索,没有结果.似乎没有允许编译deodexed系统的标志.
但是在makefile build/core/main.mk中我发现了这个:
## precise GC ##
ifneq ($(filter dalvik.gc.type-precise,$(PRODUCT_TAGS)),)
# Enabling type-precise GC results in larger optimized DEX files. The
# additional storage requirements for ".odex" files can cause /system
# to overflow on some devices, so this is configured separately for
# each product.
ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dexopt-flags=m=y
endif
Run Code Online (Sandbox Code Playgroud)
任何的想法?谢谢
我需要在C中找到脚本的启动位置.我必须检查我的脚本是从/ usr/bin还是从另一个目录启动的.我尝试过get_current_directory_name(),但是当我启动脚本时它返回我浏览的当前路径,所以如果我这样做:cd/home/myaccount/&& my-script它返回/ home/myaccount,但我需要什么是起始位置.
我有一些指针麻烦.
这是他们的声明(主要):
int *dot_positions = (int *)malloc(sizeof(int));
char *str = (char *)malloc((MAX_N + 1) * sizeof(char));
Run Code Online (Sandbox Code Playgroud)
其中MAX_N为100,并且是字符串的限制.dot_positions [0] = -1;
我在'dot_position'的第一个位置添加一个值,然后,在运行时,我调用以下函数来添加其他值.
int add_dot_to_array(int *array, int position, int array_len) {
array = (int *)realloc(array, array_len + 1);
array[array_len] = position;
return array_len + 1;
}
Run Code Online (Sandbox Code Playgroud)
在main()的末尾,我释放了指针:
free(str);
free(dot_positions);
Run Code Online (Sandbox Code Playgroud)
但这会导致我的程序崩溃.我在Windows x64机器上使用Orwell Dev-C++和Mingw.我也确定那些指针不是NULL.怎么了?提前致谢!
android ×6
c ×3
java ×3
build.gradle ×1
download ×1
gradle ×1
inputstream ×1
makefile ×1
pointers ×1
preference ×1