我有一个Activity定义为:
<LinearLayout
android:id="@+id/TabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="99"
android:orientation="vertical">
<TabHost
android:id="@+android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/TabLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@+android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="@+android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"></FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
基本上它是一个带有TextViews作为内容的TabHost.我正在使用createTabContent()动态构建这些TextViews的选项卡和内容.这很好.但在某些情况下(某些事件由带有TCP套接字的AsyncTask处理),我需要更改其中一些TextView的内容.
我确信我的问题是我对Android SDK缺乏经验的结果,但我找不到迭代TabHost并获取每个TextView的内容的方法.
我所取得的"最接近"的方法是:
TabHost th = (TabHost) findViewById(android.R.id.tabhost);
TabWidget tw = th.getTabWidget();
for (int i = 0; i < tw.getChildCount(); i++) {
LinearLayout lLayout = (LinearLayout) tw.getChildAt(i);
TextView tv = ((TextView) lLayout.getChildAt(i));
tv.append(linea);
}
Run Code Online (Sandbox Code Playgroud)
但这样做是将"linea"附加到选项卡的名称(指示符).我想将它添加到该选项卡的内容,但我找不到一种方法来检索与之关联的TextView.
任何想法将非常感谢!
---------编辑---------
虽然在下面的评论中我发布了我已经有解决方案,但我发现它无效.代码现在看起来像这样:
for (int i = 0; i < tw.getChildCount(); i++) …Run Code Online (Sandbox Code Playgroud) android android-layout android-tabhost android-view android-activity
我们知道,使用ARC我们需要__bridge将id转换为void *:
void *t = (void *)self; // ERROR: Cast of ... requires a bridged cast
void *t = (__bridge void *)self; // CORRECT
Run Code Online (Sandbox Code Playgroud)
C函数调用也是如此:
void f(void *t) {
....
}
f((void *)self); // ERROR
f((__bridge void *)self); // CORRECT
Run Code Online (Sandbox Code Playgroud)
我认为这也适用于方法,事实上,iOS 5 Tutorial中的这个Beginning ARC给出了以下示例,并说__bridge需要:
MyClass *myObject = [[MyClass alloc] init];
[UIView beginAnimations:nil context:(__bridge void *)myObject];
Run Code Online (Sandbox Code Playgroud)
但是,今天我不小心__bridge在我的一个程序中删除了一个方法调用,并且代码编译并运行没有任何问题.在__bridge上面的示例中似乎是不必要的:
[UIView beginAnimations:nil context:(void *)myObject]; // COMPILED OK
Run Code Online (Sandbox Code Playgroud)
这是正确的吗?就是__bridge在这种情况下,实际上是不必要的?或者删除它会改变代码的含义?
有时,特别是在我的应用程序中实现新功能时,我使用DDMS + HPROF来分析内存和堆使用.由于应用程序似乎没有任何性能 - ANR问题,一切顺利,最初我并不关心它 - 但现在,因为我看到它几乎总是相同的大小,我想知道该死的是什么是.
每次运行HPROF时,都会检查Leak suspects选项卡.总有一个android.graphics.Bitmap实例占用了所有已用堆的大约25%.

我想进一步了解那是什么,所以我打开了支配树,看到了这个:

所以基本上有一个巨大的byte[]实例保留了大量的堆,并且从未被释放.根据这个,我复制了byte[]它的值,将它转储到一个.data文件中,用Gimp打开,结果如下:

所以基本上,它看起来像PNG图像的"alpha(0)"部分.考虑以下事实:
byte[]始终与应用程序的开始大致相同(4个月前)drawabledrawable-xxxbyte[]android.graphics.Bitmap任何人都知道它是什么byte[]以及我是否应该做任何事情来解放它?
任何帮助赞赏!
我有以下数据.
{
deviceID: 186,
date: "2014-3-15"
}
{
deviceID: 186,
date: "2014-3-14"
}
{
deviceID: 186,
date: "2014-3-13"
}
Run Code Online (Sandbox Code Playgroud)
和一些较低的日期,如2014-3-9 , 8 ,7 ,6等.
做的时候 db.coll.remove({date:{$lte:"2014-3-5"}})
Mongo删除了15,14,13,但保持单个数字日期.这可能是由于日期是一个字符串?
我不知道如何格式化日期,所以我可以删除某个日期以下的所有日期.
它应该是一个清理过程,删除日期低于指定日期的所有文档.
我正在构建一个 Django(版本 3.0.5)应用程序,它使用mysqlclient(版本 2.0.3)作为数据库后端。此外,我编写了一个 Django 命令,该命令运行使用python-telegram-bot API 编写的机器人,因此该机器人的任务是无限期运行,因为它必须随时响应命令。
问题是大约24小时。运行机器人后(不一定一直空闲),django.db.utils.OperationalError: (2006, 'MySQL server has gone away')运行任何命令后都会出现异常。
我绝对确定 MySQL 服务器一直在运行,并且在我收到此异常时仍在运行。MySQL 服务器版本是5.7.35.
我的假设是一些 MySQL 线程老化并关闭,因此在重用它们后它们不会被更新。
有谁遇到过这种情况并且知道如何解决吗?
Traceback (most recent call last):
File "/opt/django/gip/venv/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 555, in process_update
handler.handle_update(update, self, check, context)
File "/opt/django/gip/venv/lib/python3.6/site-packages/telegram/ext/handler.py", line 198, in handle_update
return self.callback(update, context)
File "/opt/django/gip/gip/hospital/gipcrbot.py", line 114, in ayuda
perfil = get_permiso_efectivo(update.message.from_user.id)
File "/opt/django/gip/gip/hospital/telegram/funciones.py", line 33, in get_permiso_efectivo
u = Telegram.objects.get(idtelegram=userid)
File "/opt/django/gip/venv/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), …Run Code Online (Sandbox Code Playgroud) 我已经生成了一对RSA密钥(公共和私有).现在出于测试目的,我试图将String表示中的公钥导入a PublicKey以在Android项目中使用它,以便将RSA中的加密消息发送到远程服务器,然后使用私钥对它们进行解密.
public static String encryptDataRSA(final String data) throws IOException {
final byte[] dataToEncrypt = data.getBytes();
byte[] encryptedData = null;
try {
final String keyStr = "-----BEGIN PUBLIC KEY-----\n" +
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdQudusozLmogBfU2LCO+WcM59\n" +
"ycup9SxMsBNCku23PxrPMO6u//QjtWPz7istE9vkQfa6tQn1Or+SDxeHLMxEesF0\n" +
"xiBEgFUhg7vjOF2SnFQQEADgUyizUIBBn1UgKNA8eP24Ux0P0M2aHMn78HIHsRcu\n" +
"pNGUNW7p51HOVoIPJQIDAQAB\n" +
"-----END PUBLIC KEY-----";
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyStr.getBytes()));
final Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
encryptedData = cipher.doFinal(dataToEncrypt);
try {
final String encryptedText = new String(Base64.encode(encryptedData, Base64.DEFAULT), "UTF-8");
return encryptedText.toString();
}
catch (final UnsupportedEncodingException e1) { return null; } …Run Code Online (Sandbox Code Playgroud) 我写了一个 Django 应用程序,它有一个外部身份验证系统,可以在某个 URL 上访问(比如,https://.../myproject/login)。这运行良好。
但是,当会话过期时,用户会被重定向到默认登录 url,即https://.../myproject/admin)。我想更改应用程序的行为,因此如果会话过期,则应将用户重定向到https://.../myproject/login并仅/admin在显式打开时使用登录名。
在 Django 中是否有内置的方法来做到这一点?
我成功安装了imagemagic和imagick(使用 http://www.php.net/manual/en/imagick.installation.php#94169步骤)并且还放了extension = imagick.so.但是当我重新启动apache时,我得到了以下错误.
无法加载动态库/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/imagick.so
dlopen的(/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/imagick.so,
9):未加载库:/usr/local/lib/libfreetype.6.dylib引用自:
/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/imagick.so
原因:不兼容的库版本:imagick.so需要版本18.0.0或更高版本,但libfreetype.6.dylib在第0行提供了未知版本16.0.0
我在mamp下使用Mac OSX(10.8.5),php 5.5.3
任何帮助表示如何解决这个问题!谢谢
我正在尝试做这样的底层菜单:

我以这种方式定义了布局:
<LinearLayout
android:id="@+id/bottomBar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginTop="4dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- First item of the menu -->
<ImageButton
android:id="@+id/BConex1"
android:contentDescription="@string/desc_gen_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:layout_gravity="left"
android:background="@drawable/menu_bottom"
android:layout_marginLeft="4dp" />
<!-- Second item of the menu -->
<ImageButton
android:id="@+id/BConex2"
android:contentDescription="@string/desc_gen_image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:layout_gravity="left"
android:background="@drawable/menu_bottom"
android:layout_marginLeft="4dp" />
<!-- ... Some additional items in the menu -->
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
@ drawable / menu_bottom是一个层列表,用以下方式定义:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个对话框,在用户注销之前向用户显示倒计时。超时是从另一个活动设置的。
我写了以下代码:
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
public class SessionInactivityDialog extends DialogFragment {
public void setInactivityTimeout(long timeout) {
Resources res = getActivity().getResources();
String text = String.format(res.getString(R.string.iminent_logout_text), (timeout / 1000));
((AlertDialog)getDialog()).setMessage(text);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.iminent_logout);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
SessionActivity activity = (SessionActivity)getActivity();
activity.resetTimer();
}
});
return builder.create();
}
}
Run Code Online (Sandbox Code Playgroud)
使用以下几行调用该对话框:
private void showIminentLogoutDialog(long timeout) {
mInactivityDialog.show(getFragmentManager(), …Run Code Online (Sandbox Code Playgroud) android nullpointerexception android-alertdialog dialogfragment
我找到这个主题的任何地方都说(恢复):"打电话finish()给你的活动,如果你有任何服务在运行,请打电话stopService()给他们".
所以我做了,而且似乎工作,我不再担心.今天,调试我的代码的一部分,我需要在Log非结束线程的方法中添加一行,我想要执行所有应用程序的生命,基本上它是这样的:
final Thread buf_liberator = new Thread(
new Runnable() {
public void run() {
while (true) {
methodCall();
SystemClock.sleep(9000);
}
}
}
);
buf_liberator.setPriority(7);
buf_liberator.start();
Run Code Online (Sandbox Code Playgroud)
在methodCall()我放Log线时,令我惊讶的是,在我关闭我的应用程序后按下退出按钮调用finish()并停止我已启动的服务,我仍然Log在LogCat中每隔9秒无限期地看到该消息.
所以问题是(是):这个线程不是服务,为什么它一直在运行?难道我做错了什么?这是预期的行为吗?是否有一种真正的方法来摧毁应用程序在内存中的所有内容?
谢谢!
如何检测是否WiFi已打开,以决定是否通过android客户端将数据传输到服务器?
在使用网络服务的android设备上,首先android设备会检查WiFi打开或关闭状态,然后在WiFi关闭状态下将数据存储在数据库或其他资源中,并且一旦打开/启用WiFi即可获取数据开始传输到服务器。
应该使用什么来实现这一目标?
android ×7
django ×2
java ×2
android-view ×1
bridge ×1
date ×1
ddms ×1
encryption ×1
exit ×1
hprof ×1
imagemagick ×1
imagick ×1
ios ×1
macos ×1
mamp ×1
memory-leaks ×1
mongodb ×1
mysql ×1
mysql-python ×1
objective-c ×1
php ×1
python ×1
xml ×1