我想知道当前的页面位置ViewPager
.我创建一个适配器并将此适配器设置为ViewPager
.现在我想知道当前视图的当前页码或位置,因为我想在该特定页面上启动一些额外的事件.
我用来viewPager.setCurrentItem(1);
设置第一项.
获取当前页面是否有类似的方法?
这里我有一个视图分页器活动,它有一个imageview和2个覆盖条.我使用android xml文件布局本身制作了覆盖条.
我的要求就是这样
1)第一次单击视图寻呼机的imageview =显示顶部和底部矩形覆盖栏.2)第二次单击视图寻呼机的imageview =隐藏这些叠加.
这两个都是像android gallary视图类型的功能.
但是,当这时显示这些顶部和底部布局栏时,我只想使用按钮,只需单击此布局中声明的按钮.
但是我没有成功实现这个目标.
问题
1)什么时候top or bottom bar
如果我可以点击next or previous
按钮而不是它后面的imageview单击触摸事件的事件,我的酒吧变得不可见.2)只需要声明按钮事件3)当我触摸覆盖条时,避免单击视图.
简而言之,当我的顶部和底部图像条出现时,从顶部和底部图像条没有发生图像查看事件.我可以点击imageview,但是当我实际点击下一个或上一个或分享按钮时,我不能点击.
所以这些是我面临的问题,请帮助我.
源代码 :
activity_pager_image.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="@+id/rl_top_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/slideshow_bar"
android:visibility="gone" >
<TextView
android:id="@+id/tv_top_overlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textIsSelectable="false" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_bottom_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/slideshow_bar"
android:visibility="visible" >
<Button
android:id="@+id/btn_left_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="35dp"
android:background="@drawable/ic_left_arrow" />
<Button
android:id="@+id/btn_below_share"
style="@style/normalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="35dp" …
Run Code Online (Sandbox Code Playgroud) android android-layout android-gui android-viewpager android-framelayout
我想知道关于Android应用程序的twitter api ....请发给我关于twitter api的链接或来源api只是为了发送推文....
我正在尝试实现一个EditText
限制仅限数字[A-Z0-9]的数字输入的输入.
我从一些帖子开始使用InputFilter方法.但是我在三星Galaxy Tab 2上遇到了一个问题,但在模拟器或Nexus 4中却没有.
问题是这样的:
简而言之,它重复着色
这是我正在使用此代码的代码:
public class DemoFilter implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
int dend) {
if (source.equals("")) { // for backspace
return source;
}
if (source.toString().matches("[a-zA-Z0-9 ]*")) // put your constraints
// here
{
return source.toString().toUpperCase();
}
return "";
}
}
Run Code Online (Sandbox Code Playgroud)
XML文件代码:
<EditText
android:id="@+id/et_licence_plate_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="0"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:maxLength="3"
android:singleLine="true"
android:textSize="18px" >
</EditText>
Run Code Online (Sandbox Code Playgroud)
我完全坚持这个,所以在这里任何帮助将不胜感激.
我在我的应用程序中使用强制转换功能.它工作正常但突然间我可以看到Play商店控制台上崩溃次数的增加.
我正在按照指南中的定义正确初始化CastContext.此外,我在调用此方法之前检查设备是否兼容CastContext.getSharedInstance(context)
所以这应该不是问题.
即使在使用或不使用google-play-services的模拟器上,我也无法重现此崩溃.
任何帮助将不胜感激.
崩溃:
致命异常:java.lang.RuntimeException:无法启动活动ComponentInfo {....activity.TVActivityPhone}:java.lang.RuntimeException:com.google.android.gms.dynamite.DynamiteModule $ zza:远程加载失败.没有发现本地回退.在Android.app.A活动中的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)android.app.A活动.活动(活动传递.) .ActivityThread $ H.handleMessage(ActivityThread.java:1584)在android.app.Loper.loop(Looper.java:194)的android.app.Handler.dispatchMessage(Handler.java:111)android.app.ActivityThread. main(ActivityThread.java:5877)位于java.lang.reflect.Method.invoke(Method.java)的java.lang.reflect.Method.invoke(Method.java:372),位于com.android.internal.os.ZygoteInit com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)中的$ MethodAndArgsCaller.run(ZygoteInit.java:1020)由java.lang.RuntimeException引起:com.google.android.gms.dynamite.DynamiteModule $ zza:远程加载失败.没有发现本地回退.
代码我在条件中收到错误,如果条件意味着,它不是关于谷歌播放服务的可用性.
if (googlePlayServicesVerified(context)) { // checking (result==ConnectionResult.SUCCES)
Log.d("TAG", "instantiated");
castContext = CastContext.getSharedInstance(context);
} else {
Log.e(TAG, "FAILED");
}
Run Code Online (Sandbox Code Playgroud)
提交给谷歌的bug:
https://issuetracker.google.com/issues/65359941
**更新**检查以下两个问题:
https://issuetracker.google.com/issues/65359941 https://issuetracker.google.com/issues/79405933
临时解决方案在我的回答中.
stackoverflow上有关于这个主题的问题很少,但我没有得到正确的答案.我对平面文件的性能有一些疑问,使用平面文件而不是SQLite更好吗?
我获取了Android的性能统计数据SQLite
.
我有一个表有21列的性能统计信息
任何人都可以建议如何减少这个插入时间.
Records Write time in ms Read time in ms
1000 67813 608
1000 66340 604
1000 64359 609
10000 679837 5159
10000 618062 5110
10000 644638 5729
10000 646878 5890
Run Code Online (Sandbox Code Playgroud)
Flat file
没有时间而不是 SQLite
所以有人请建议我如何为SQLite改善这段时间.
我使用简单database open insert using ContentValues
和数据库关闭.
请告诉我一些如何改进这些统计数据的方法.
使用下面的答案后更新了性能统计数据.我想提高这些性能.
Records Writetime in ms Readtime in ms
1000 1645 530
1000 2497 672
1000 3143 610
10000 16356 5243
10000 14006 5122
10000 13158 5002
10000 14828 5234
100000 125525 …
Run Code Online (Sandbox Code Playgroud) 从Android O(API 26)版本引入的通知渠道.我从以下链接中了解到它:
问题:
如果我有多个通知数,那么在应用程序启动时创建通知通道并将其保留在最佳状态是否是个好主意ApplicationScope
?
public void addNotificationChannels(Context context) {
List<NotificationChannel> channels = new ArrayList<>();
channels.add("channel_1");
channels.add("channel_2");
.
.
channels.add("channel_7");
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannels(channels);
}
Run Code Online (Sandbox Code Playgroud)如果我new Notification.Builder(getApplicationContext(), PRIMARY_CHANNEL)
在将通道添加到通知管理器之前尝试执行此行,会发生什么
android android-notifications android-8.0-oreo notification-channel
我必须允许用户只在##中输入时间:##格式即时编辑文本,有什么办法可以实现吗?我使用下面的代码,但它不起作用.
我能输入超过24的数字,如45623:5689.
edit.setInputType(InputType.TYPE_DATETIME_VARIATION_TIME)
Run Code Online (Sandbox Code Playgroud)
甚至android:text="time"
也没有用.
我怎么能实现这个目标.任何人都可以建议我怎么做这件事.
我想允许用户输入前2个位置,最多23个值然后compulasary:然后用户可以允许最多59个值.
例如
23:59 correct
24:05 incorrect
02:56 correct
02:79 incorrect
Run Code Online (Sandbox Code Playgroud)
我也使用了这个自定义过滤器,但它不起作用
我从SO的其他地方得到了这个代码.
码:
InputFilter timeFilter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
int dstart, int dend) {
if (source.length() == 0) {
return null;// deleting, keep original editing
}
String result = "";
result += dest.toString().substring(0, dstart);
result += source.toString().substring(start, end);
result += dest.toString().substring(dend, dest.length());
if (result.length() > 5) {
return "";// do not allow this …
Run Code Online (Sandbox Code Playgroud) 在这段代码中,我传递了一个字符指针引用函数test,并在函数test I malloc size中写入数据并将数据写入该地址,然后打印出来并得到null值.
#include <stdio.h>
#include <stdlib.h>
void test(char*);
int main()
{
char *c=NULL ;
test(c);
printf("After test string is %s\n",c);
return 0;
}
void test(char *a)
{
a = (char*)malloc(sizeof(char) * 6);
a = "test";
printf("Inside test string is %s\n",a);
}
Run Code Online (Sandbox Code Playgroud)
输出:
Inside test string is test
After test string is (null)
Run Code Online (Sandbox Code Playgroud)