我试图让这个工作:我基本上想在一个ViewPager中使用两个Recyclerviews.我遵循了这个教程:http://android-java-development.blogspot.de/2012/05/system.html,但它似乎不起作用.我看起来视图寻呼机是空的,并且回收器视图没有显示出来.
这是我的布局代码:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/pager_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/tab_height">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/accent"/>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
而我的PageAdapter:
public class NewsPagerAdapter extends PagerAdapter {
private Context context;
private Vector<RecyclerView> recyclerViewList;
private String[] titles;
public NewsPagerAdapter(Context context, int titlesId) {
this.context = context;
this.recyclerViewList = new Vector<>();
setTitles(titlesId);
}
public void add(RecyclerView recyclerView) {
recyclerViewList.add(recyclerView);
}
public RecyclerView.Adapter getAdapterForViewAtIndex(int index) {
return recyclerViewList.get(index).getAdapter();
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(recyclerViewList.get(position),
new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)
);
return container;
}
@Override …Run Code Online (Sandbox Code Playgroud) java android listview android-viewpager android-recyclerview
我目前正在开发一个Android应用程序,它依赖于SyncAdapter从服务器刷新其内容.我基本上遵循了这些说明:https://developer.android.com/training/sync-adapters/creating-sync-adapter.html
直到最近,这仍然很好.我知道这可能听起来很愚蠢,但老实说我不知道我是怎么搞砸的:(
我有一个ContentProvider,因此SyncAdapter我想要同步的所有项目的一个和一个帐户.我使用整数标志来确定哪个项目必须同步:
public static final int EVENTS = 0x1;
public static final int NEWS = 0x2;
public static final int SUBSTITUTIONS = 0x4;
public static final int TEACHERS = 0x8;
public static final int ALL = 0xF;
Run Code Online (Sandbox Code Playgroud)
所以在我看来onPerformSync我有类似的东西:
ArrayList<ContentProviderOperation> batchList = new ArrayList<>();
int which = extras.getInt(SYNC.ARG, SYNC.ALL);
if((which & SYNC.NEWS) == SYNC.NEWS) { syncNews(provider, batchList, syncResult, 0, 1); }
if((which & SYNC.EVENTS) == SYNC.EVENTS) { syncEvents(provider, …Run Code Online (Sandbox Code Playgroud) android synchronization android-contentresolver android-syncadapter swiperefreshlayout
我想使用带有保存和管理RecyclerView的片段的ViewPager实现简单的滑动导航.
片段已创建并可使用切换setCurrentItem(),但您无法向左或向右滑动以切换页面.ViewPager似乎忽略了任何滑动手势.
我的活动布局:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>
<android.support.v7.widget.Toolbar
... />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我使用FragmentPagerAdapter我onCreate()喜欢的方式填充ViewPager :
viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.addOnPageChangeListener(this);
viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new Dummy2Fragment();
case 1:
return new Dummy2Fragment();
default:
return null;
}
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
return "Dataset " + (position + 1);
}
}); …Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments android-viewpager android-recyclerview
我在我的操作栏中有一个搜索视图,我希望在方向更改后恢复查询.我怎样才能做到这一点?使用捆绑包设置查询SearchView.setQuery(query, false);不起作用,因为searchview ""会在扩展后立即将其查询设置为.
下面是我的相关代码onActivityCreated:
if(savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_KEY_SEARCH))
mCurFilter = savedInstanceState.getString(BUNDLE_KEY_SEARCH);
Run Code Online (Sandbox Code Playgroud)
在这里我的onSaveInstanceState:
savedInstanceState.putString(BUNDLE_KEY_SEARCH, mCurFilter);
super.onSaveInstanceState(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)
那么我怎么能恢复它的状态,因为我无法使用它setQuery?谢谢大家
我想在我的 lwjgl3 java 应用程序中实现 FPS 风格的鼠标外观,但由于没有任何Mouse.getDX()or Mouse.getDY(),我正在寻找使用 glfw 绑定的不同方法。我编写了在我的方法中调用的方法update():
public double[] pollMouseDelta() {
DoubleBuffer x = BufferUtils.createDoubleBuffer(1);
DoubleBuffer y = BufferUtils.createDoubleBuffer(1);
glfwGetCursorPos(WINDOW, x, y);
x.rewind();
y.rewind();
double tempX = mouseX;
double tempY = mouseY;
mouseX = x.get();
mouseY = y.get();
return new double[] {
mouseX - tempX,
mouseY - tempY
};
}
Run Code Online (Sandbox Code Playgroud)
其中mouseX和mouseY是全局变量。
在我的更新方法中,我执行以下操作:
double[] mouseDelta = pollMouseDelta();
camera.rotate(Camera.Direction.LEFT_RIGHT, (float) (0.2f * -mouseDelta[0]));
camera.rotate(Camera.Direction.UP_DOWN, (float) (0.2f * mouseDelta[1]));
camera.update();
Run Code Online (Sandbox Code Playgroud)
我也将GLFW_CURSOR …