我们假设已经加载了一个url(我们称之为原始url).
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/missing.html");
}
});
Run Code Online (Sandbox Code Playgroud)
我创建了自己的错误页面,以防止出现"网页不可用消息".应用程序必须在每次恢复时重新加载webview.所以我有以下几行代码:
@Override
protected void onResume() {
super.onResume();
webView.reload();
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是,当加载错误页面时(例如,当用户未连接到互联网时),然后再次可用连接并且用户恢复应用程序时,原始URL未加载(这似乎是逻辑,现在的电流正在丢失.但这是一个很好的方法吗?有什么问题的建议吗?
如果用户想要重新加载内容,还有一个刷新按钮.同样的问题在这里
如果在我的数据库中首先创建行失败,我想阻止向Select2元素添加类别.当我调用ev.preventDefault()时,不会阻止该操作; 什么都没发生..有什么不对?
$('#sel2').select2({
placeholder: 'Enter categories',
minimumInputLength: 3,
multiple: true,
ajax: {
url: 'async/get_categories.php',
dataType: 'json',
quietMillis: 250,
data: function (term, page) {
return {
q: term,
};
},
results: function (data, page) {
return {
results: data.items
};
},
cache: true
},
formatResult: format,
formatSelection: format
}).on('select2-selecting', function(e) {
console.log(e);
if (e.val == 4) {
// if category id equals 4
// do not add this category to select 2
// e.preventDefault();
// the above works just fine and …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个需要用户身份验证的应用程序 用户首次打开应用程序时应登录或注册以继续加载某些帖子的应用程序的主屏幕.
我应该提到主屏幕应该是一个FragmentActivity,允许用户在2-3个选项卡之间导航..这意味着我应该有另一个Activity(用于登录屏幕或注册),以允许用户以后继续回家.
MainActivity
|
|
--> Check If user logged in
| |
| |
| --> Start Login Activity (Or Register From Here)
|
--> Start Home Activity (FragmentActivity with 2-3 tabs-fragments)
Run Code Online (Sandbox Code Playgroud)
现在在主Activity中我正在检查共享首选项,如果用户已经登录,然后我启动FragmentActivity或登录Activity如果用户尚未登录.
我不知道这是否是一个问题,但当这两个活动中的一个已经开始,如果我按回它,它会在一个空白屏幕上,没有任何反应.似乎是逻辑,因为这是MainActivity,它实际上是空白的.我只有if语句才能进行适当的活动.
这是一个很好的方法还是我应该用另一种方式来开发它?
我有一个ListView
使用扩展的自定义适配器的自定义适配器BaseAdapter
。在此自定义适配器中,我有一个视图支架,用于容纳每个列表项中显示的项。
我可以得到一定的列表项的孩子的点击回调View
IN 的Activity
,我创建和填充我的ListView
?
我试图重写网站的网址,我应该提到index.php现在的工作方式是获取p(页面)参数并包含相应的文件.
所以请求页面是这样的:
www.domain.com/index.php?p=home
www.domain.com/index.php?p=search
www.domain.com/index.php?p=profile
www.domain.com/index.php?p=contact
Run Code Online (Sandbox Code Playgroud)
我找到了如何为此创建重写规则:
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?p=$1
Run Code Online (Sandbox Code Playgroud)
所以现在www.domain.com/home会给我主页
但我还需要一个友好的网址
www.domain.com/index.php?p=profile&id=20
to
www.domain.com/profile/20/profile-friendly-name
or better
www.domain.com/profile/profile-friendly-name
Run Code Online (Sandbox Code Playgroud)
*个人资料友好名称是指公司名称
要求:
为所有页面提供友好的URL,例如/ home,/ contact
为个人资料页面提供特定的友好网址,并在网址中包含个人资料名称
我的问题:
如何使用现有的url格式(index.php?p = profile&id = 20)向url添加profile-friendly-name?
我可以只有一个唯一的名称(没有id),就像我上一个例子一样吗?
如果我设法做到这一点,我是否必须将网站中的所有现有网址(链接,网址到图片,文件)更改为友好格式?
我注意到在应用第一个RewriteRule后,一些css样式表和js不包括在内.怎么了?
我有以下两个实体:
档案,类别
在配置文件实体中,我有一个配置文件具有的类别列表
在类别实体中,我有一个类别列表
生成的表称为profiles_has_categories,并具有以下列:
profile_id,category_id
我想找到属于任何类别的所有配置文件,其中包含以下ID 1,2,3,4
我会在普通的sql中用:
SELECT p.* FROM profiles p, profiles_has_categories phc
WHERE p.id = phc.profile_id
AND phc.category_id IN (1, 2, 3, 4)
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何使用CriteriaBuilder在JPA中构建一个查询:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Profile> criteria = cb.createQuery(Profile.class);
Root<Profile> root = criteria.from(Profile.class);
// Profile_.categories is a collection of Category objects
// categories is collection of Long (category ids) that i want to search in
// but is not working
criteria.where(root.get(Profile_.categories).in(categories))
List<Profile> results = em.createQuery(criteria).getResultList();
Run Code Online (Sandbox Code Playgroud) 为视图创建动画..来自developer.android.com:
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
spaceshipImage.startAnimation(hyperspaceJumpAnimation);
Run Code Online (Sandbox Code Playgroud)
我想知道我是否可以扩展ImageView所以我创建的每个MyImageView在点击时都会有动画.
我还应该在MyImageView类之外为每个MyImageView设置一个不同的OnClickListener.
那可能吗?
我正在使用DataTables:
$t = $('#users-table').DataTable({
'paging' : true,
'searching' : true,
'ordering' : false,
'info' : false,
'serverSide': true,
'processing': true,
'ajax' : {
'url' : 'http://localhost/api/users',
'type' : 'GET',
'dataSrc' : 'users',
'error': function() {
// how can i handle the 404 response and show the no results found message?
}
}
...
Run Code Online (Sandbox Code Playgroud)
如果查询没有结果,服务器将返回404未找到的响应.我正在尝试显示无结果消息并从表中删除当前数据,但相反,数据将在表中保持相同的错误响应.
编辑:
我正在使用这样的搜索功能:
$('#data-filter').keyup(function() {
$t.search($(this).val()).draw();
});
Run Code Online (Sandbox Code Playgroud)
因此,如果未找到查询字的结果,则返回404.