我有一个包含ListView的子Activity.此活动是从SQLite游标异步填充的.列表项包含TextView,RadioButton和普通Button.XML如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/rlCategoryListItemLayout" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/tvCategoryListItemTitle" style="@style/uwLargeListItemLabelStyle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:singleLine="true" android:text="This is a test note title" />
<LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:gravity="center_vertical">
<RadioButton android:id="@+id/rdoCategoryListItemSelect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginRight="10dip" />
<Button android:id="@+id/btnCategoryListItemDelete" android:background="@drawable/delete_red" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我必须做一些逻辑来确定默认选择哪个RadioButton,并且在ListView已经加载之前我不能这样做.问题是,到目前为止我尝试过的所有事件(onCreate,onPostCreate,onResume,onWindowFocusChanged),ListView子计数为零.我也尝试在ArrayAdapter类中使用getView方法,但该方法被称为多个时间,并且ListView子计数每次都可能不同,从而导致意外结果.显然,这些事件在ListView完成填充其子项之前触发.
是否有我可以侦听的事件,或者其他一些方法来确定ListView何时完成填充并且可以通过编程方式修改其所有子代?
谢谢!
我使用以下方法从我的Android应用程序中的assets文件夹中提取PNG文件:
public static Bitmap getBitmapFromAssets(Context context, String fileName) {
try {
AssetManager assetManager = context.getAssets();
InputStream inputStream = assetManager.open(fileName);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
return bitmap;
}
catch(Exception ex) {
ex.printStackTrace();
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在GridView的项目中将ImageView的源设置为该Bitmap.
这是有问题的布局XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/containingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:background="@android:color/transparent"
android:padding="0dp"
android:layout_margin="0dp"
>
<ImageView
android:id="@+id/ivPackageIcon"
style="@style/smLargeGridItemPackageIconStyle"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
该XML中提到的样式是:
<style name="smLargeGridItemPackageIconStyle">
<item name="android:scaleType">fitXY</item>
<item name="android:layout_width">100dp</item>
<item name="android:layout_height">142dp</item>
<item name="android:layout_margin">5dp</item>
<item name="android:background">@android:color/transparent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
以下是设置ImageView源代码:
ImageView ivPackageIcon = (ImageView)containingView.findViewById(R.id.ivPackageIcon);
if(ivPackageIcon != null) {
Bitmap coverImage = getBitmapFromAssets(containingView.getContext(), "myimage.png"); …Run Code Online (Sandbox Code Playgroud) 我编写了一个工具来修复一些XML文件(即插入一些缺少的属性/值),使用C#和Linq-to-XML.该工具将现有XML文件加载到XDocument对象中.然后,它通过节点向下解析以插入缺失的数据.之后,它调用XDocument.Save()将更改保存到另一个目录.
所有这一切都很好,除了一件事:任何 XML文件中文本中的实体将替换为换行符.当然,实体代表一个新行,但我需要在XML中保留实体,因为另一个消费者需要它.
有没有办法保存修改后的XDocument而不会丢失 实体?
谢谢.
我遇到了一个奇怪的问题.我正在对HTC EVO进行测试.我编写了一个针对2.2的演示相机应用程序,几乎一切都正常.问题是,在拍摄三到四张照片后,应用程序崩溃并给我以下消息:
D/QualcommCameraHardware( 64): takePicture(479)
D/QualcommCameraHardware( 64): val_ril_status = 0,val_wimax_status = 0,val_hotspot_status = 0,val_low_temp_limit = 10.000000,val_batt_temp = 29.799999,val_low_temp_limit = 15,val_batt_cap = 96
D/QualcommCameraHardware( 64): FLASHLIGHT is ENABLED
D/QualcommCameraHardware( 64): stopPreviewInternal E: 1
D/QualcommCameraHardware( 64): cancelAutoFocusInternal E
D/QualcommCameraHardware( 64): cancelAutoFocusInternal X: 0
I/QualcommCameraHardware( 64): deinitPreview E
D/QualcommCameraHardware( 64): launch_watchdog_thread:
D/QualcommCameraHardware( 64): watchdog_thread_id = 369048
I/QualcommCameraHardware( 64): register_buf: camfd = 35, reg = 1 buffer = 0x4153f000
I/QualcommCameraHardware( 64): register_buf: camfd = 35, reg = 1 buffer = 0x415bf000
I/QualcommCameraHardware( 64): register_buf: …Run Code Online (Sandbox Code Playgroud) 我使用以下URL提供的代码尝试使用Android Camera API:
http://marakana.com/forums/android/examples/39.html
这提出了几个问题,我试图找到目前为止的答案是徒劳的.
1)我的应用程序需要处于纵向方向,但我所看到的所有代码示例(包括上面提到的URL)似乎都依赖于横向方向.事实上,无论我到目前为止尝试过什么,似乎景观都是不可避免的.我试过surfaceCreated(...)像这样强制参数:
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.set("rotation", "90");
camera.setParameters(parameters);
Run Code Online (Sandbox Code Playgroud)
我试过做同样的事情surfaceChanged(...).当然,我也在清单中将我的方向设置为肖像如下:
android:screenOrientation="portrait"
Run Code Online (Sandbox Code Playgroud)
有没有人对我做错了什么以及如何解决它有任何建议?
2)我发布的另一个问题与释放相机资源有关.在上面引用的文章的代码中,在surfaceDestroyed(...)方法中调用以下内容:
camera.stopPreview();
camera = null;
Run Code Online (Sandbox Code Playgroud)
没有什么可以释放相机资源,因此在运行此应用程序后,任何使用相机的后续应用程序都将无法工作.我试图解决这个问题,我添加了一个释放资源的调用,如下所示:
camera.stopPreview();
camera.release();
camera = null;
Run Code Online (Sandbox Code Playgroud)
但问题是,当我关闭应用程序时,我在LogCat中遇到以下异常的"强制关闭":
FATAL EXCEPTION: main
java.lang.RuntimeException: Method called after release()
at android.hardware.Camera.setHasPreviewCallback(Native Method)
at android.hardware.Camera.access$600(Camera.java:58)
at android.hardware.Camera.$EventHandler.handleMessage(Camera.java:344)
at android.os.Handler.dispatchMessage(Handler.java.99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lanf.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么我不能在那里释放相机资源?
谢谢大家.这个相机的东西让我疯了.
PS我正在HTC Evo上测试所有这些.
我几乎得到了答案,但我错过了一些东西,我希望有人可以帮助我.
我需要一个正则表达式,它将匹配句子中每个单词的第一个字母.然后我需要用正确数量的星号替换匹配的字母.例如,如果我有以下句子:
There is an enormous apple tree in my backyard.
Run Code Online (Sandbox Code Playgroud)
我需要得到这个结果:
T**** i* a* e******* a**** t*** i* m* b*******.
Run Code Online (Sandbox Code Playgroud)
我设法想出一个几乎可以做到的表达式:
(?<=(\b[A-Za-z]))([a-z]+)
Run Code Online (Sandbox Code Playgroud)
使用上面的例句,该表达式给了我:
T* i* a* e* a* t* i* m* b*.
Run Code Online (Sandbox Code Playgroud)
如何获得正确数量的星号?
谢谢.
如何在 XQuery 中删除一组标签但仍将其文本保留在那里?例如,如果我有:
<root>
<childnode>This is <unwantedtag>some text</unwantedtag> that I need.</childnode>
</root>
Run Code Online (Sandbox Code Playgroud)
如何去除不需要的标签以获得:
<root>
<childnode>This is some text that I need.</childnode>
</root>
Run Code Online (Sandbox Code Playgroud)
实际上,我真正想要结束的只是文本,例如:
This is some text that I need.
Run Code Online (Sandbox Code Playgroud)
当我执行以下操作时:
let $text := /root/childnode/text()
Run Code Online (Sandbox Code Playgroud)
我得到:
This is that I need.
Run Code Online (Sandbox Code Playgroud)
它缺少它的some text一部分。
关于如何返回的任何想法This is some text that I need.?
谢谢你。
我正在开发一个依赖于相机API的Android应用程序,使用HTC EVO作为我的测试设备.无论我到目前为止尝试过什么,相机预览看起来正确的唯一时间是横向模式(90度旋转,具体而言).在纵向模式(0度旋转)下,似乎没有办法正确定位预览.
设备上的默认摄像头应用程序(用于HTC Sense)允许任何类型的旋转而没有任何问题,因此我知道没有硬件限制.我甚至从HTC的开发者网站下载了一些源代码,但显然它都是在C内核中.
谁能指出我正确的方向来解决这个问题?有没有办法在Android 2.1或2.2中正确旋转预览?
谢谢.
PS这是我正在使用的代码,如果它有帮助......
package spikes.cameraSpike03;
import java.util.List;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity implements SurfaceHolder.Callback {
private static final String LOG_TAG = "spikes.cameraSpike03 - MainActivity";
private Camera _camera;
private boolean _previewIsRunning = false;
private SurfaceView _svCameraView;
private SurfaceHolder _surfaceHolder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
_svCameraView = …Run Code Online (Sandbox Code Playgroud) camera android orientation android-sdk-2.1 android-2.2-froyo
考虑以下XML片段:
<doc>
<chapter id="1">
<item>
<para>some text here</para>
</item>
</chapter>
</doc>
Run Code Online (Sandbox Code Playgroud)
在 中XQuery,我有一个函数需要根据作为参数传入的给定“para”元素的祖先章节执行一些操作,如下面的精简示例所示:
declare function doSomething($para){
let $chapter := $para/ancestor::chapter
return "some stuff"
};
Run Code Online (Sandbox Code Playgroud)
在该示例中,$chapter始终显示为空。但是,如果我编写类似于以下的函数(即不使用祖先 axis),我会得到所需的“章节”元素:
declare function doSomething($para){
let $chapter := $para/../..
return "some stuff"
};
Run Code Online (Sandbox Code Playgroud)
问题是我不能像后一个示例中那样使用显式路径,因为XMl我将要搜索的内容不能保证每次都将“chapter”元素作为祖父母。它可能是曾祖父母或曾曾祖父母,等等,如下所示:
<doc>
<chapter id="1">
<item>
<subItem>
<para>some text here</para>
</subItem>
</item>
</chapter>
</doc>
Run Code Online (Sandbox Code Playgroud)
有谁能解释为什么轴不起作用,而显式 XPath 却起作用?另外,有人对如何解决这个问题有什么建议吗?
谢谢。
现在这个谜团已经解开了。
有问题的节点是在另一个函数中重新创建的,其结果是剥离了它的所有祖先信息。不幸的是,以前的开发人员没有记录这个奇妙的小功能,并且花费了我们很多时间。
因此,祖先轴完全按照其应有的方式工作 - 它只是应用于欺骗性节点。
我感谢大家为回答我的问题所做的努力。
android ×5
camera ×2
orientation ×2
xml ×2
xquery ×2
api ×1
axes ×1
c# ×1
entity ×1
events ×1
exception ×1
linq-to-xml ×1
listview ×1
lookahead ×1
lookbehind ×1
marklogic ×1
png ×1
populate ×1
regex ×1
release ×1
strip-tags ×1
text ×1
transparency ×1
transparent ×1
xpath ×1