我创建了自己的WebView并设置了WebChromeClient和WebViewClient对象.当我启动此WebView时,HTML表单字段在我触摸它们时会产生反应(光标出现),但它们不会被选中,软键盘也不会启动.如果我使用轨迹球选择表格并按下它,键盘就会出现.
我试着打电话给myWebview.requestFocusFromTouch()为这个答案建议,但它返回false,并没有帮助.
它在TableLayout的文档中说"单元格可以跨越列,就像它们可以在HTML中一样".但是,我找不到任何办法.
具体来说,我有一行有两列,另一行有一列.我希望一列行跨越整个表.看起来很简单,但我没有看到它.
我有一个包含CheckBox的列表项,我希望能够单击CheckBox和列表项本身.不幸的是,两者之间似乎存在某种冲突,因为我只能在注释掉CheckBox时单击该项.我好像记得有办法解决这个问题,但目前我找不到它.谢谢
编辑:这是一个ListFragment,所以没有必要调用setOnItemClickListener.
好的,这是列表项的XML.问题是CheckBox,但我想也可以复制一切.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_survey"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/SimpleListItem">
<TextView
android:id="@+id/survey_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/ListItemTitle" />
<TextView
android:id="@+id/survey_date"
android:layout_below="@id/survey_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/ListItemSubtitle" />
<TextView
android:id="@+id/survey_completed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/survey_title"
android:textColor="@color/accent_1"
android:text="@string/survey_completed"
style="@style/ListItemSubtitle" />
<CheckBox
android:id="@+id/survey_did_not_attend"
android:layout_below="@id/survey_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/survey_did_not_attend"
android:focusable="false"
style="@style/ListItemSubtitle" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我必须做一些明显的事情,但我无法弄清楚它是什么.我只是想在可编辑中插入一个字符:
@Override
public void afterTextChanged(Editable s) {
Log.d(TAG, "inserting space at " + location);
s.insert(location, " ");
Log.d(TAG, "new word: '" + s + "'");
}
Run Code Online (Sandbox Code Playgroud)
但是永远不会改变.字符串's'足够长,因为我打印它看起来很好.如果我调用Editable.clear(),它将被清除,我可以用Editable.replace()替换多个字符.想法?
我想在LinearLayout的底部放置一个布局,但我似乎无法让它工作.我知道我可以使用RelativeLayout来做到这一点,但我应该可以使用LinearLayout,不应该吗?
编辑:实际上这比我想象的更令人困惑.下面的布局是简化的.实际上,我正在使用兼容层在3.0之前的设备上使用片段.
我使用Hierarchy Viewer来检查发生了什么,并发现android.support.v4.app.NoSaveStateFrameLayout已添加到我的布局中,并且该布局将layout_height设置为wrap_content.这似乎是造成我的问题的原因,但我还没弄清楚如何解决它.
具体来说,为什么这不起作用?layout_gravity不应该把它放在底部吗?
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
... stuff here ...
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal">
... more stuff here ...
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
顺便说一句,将layout_height更改为fill_parent或设置layout_weight似乎也不起作用.我只是想更好地了解发生了什么,因为很明显我错过了一些重要的东西.谢谢.
我有一些代码,用户在屏幕上绘制内容,我想将其作为PNG存储在byte []中.但是,compress()方法返回false.知道为什么会这样吗?是否有更好的方法来获取byte []?
Bitmap bm = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ALPHA_8);
Canvas c = new Canvas(bm);
c.drawPath(mSignaturePath, mSignaturePaint);
ByteArrayOutputStream out = new ByteArrayOutputStream();
if (bm.compress(Bitmap.CompressFormat.PNG, 100, out)) {
byte[] result = out.toByteArray(); // Never gets called
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我有一个Handler,它在收到特定消息时显示DialogFragment.这通常有效,但如果片段已经保存,我会收到以下错误:
E/AndroidRuntime(3898):FATAL EXCEPTION:main E/AndroidRuntime(3898):java.lang.IllegalStateException:在onSaveInstanceState E/AndroidRuntime(3898)之后无法执行此操作:at android.support.v4.app.FragmentManagerImpl.checkStateLoss (FragmentManager.java:1299)E/AndroidRuntime(3898):在android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1310)E/AndroidRuntime(3898):在android.support.v4.app.BackStackRecord .commitInternal(BackStackRecord.java:541)E/AndroidRuntime(3898):在android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525)E/AndroidRuntime(3898):at android.support.v4.app .DialogFragment.show(DialogFragment.java:123)E/AndroidRuntime(3898):at com.malauzai.app.BaseActivity $ 2.handleMessage(BaseActivity.java:72)E/AndroidRuntime(3898):at android.os.Handler.在DispatchMessage(Handler.java:99)
现在,我知道这是预期的,基于Javadoc for FragmentManager.beginTransaction:
注意:只能在活动保存其状态之前创建/提交片段事务.如果您尝试在Activity.onSaveInstanceState()之后(以及之后的Activity.onStart或Activity.onResume()之前提交事务,则会出现错误.这是因为框架负责将当前片段保存在状态中,如果在状态保存后进行了更改,则它们将丢失.
我的问题是,我不知道如何防止它.我试过打电话Handler.removeMessages()的onPause(),但它仍然存在.我已尝试设置一个标志,onSaveInstanceState()如果已设置则不显示该片段,但它仍然会发生.这似乎是一个非常常见的问题,但我无法想出一个有效的解决方案.基本上,我如何知道该片段已被保存?
顺便说一句,这发生在我的BaseActivity(扩展FragmentActivity)上,但是每个活动都有自己的处理程序,所以我认为这不应该是一个问题.
我最后的想法是使用Fragment.commitAllowingStateLoss(),但这似乎是一个黑客.
编辑: 这是导致我出现问题的代码:
private final Handler mTimerHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case TIMER_MESSAGE_LOGOUT_WARNING:
// throws IllegalStateException if fragment is already saved
new LogoutWarningDialog().show(getSupportFragmentManager(),
"dialog");
break;
}
}
};
Run Code Online (Sandbox Code Playgroud) android android-fragments android-dialog android-dialogfragment