我在androidTest文件夹中创建了一个虚拟活动,并在androidTest文件夹中的AndroidManifest文件中声明了该活动.
我的基本目的是通过使用framelayout容器将其放入虚拟活动来测试可重用片段.
AndroidManife文件夹里面的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.droid.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="18"
tools:overrideLibrary="android.support.test.uiautomator.v18" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.droid" />
<application>
<uses-library android:name="android.test.runner" />
<activity
android:name="com.droid.DummyActivityForTest"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
我的测试类TestWidgets.java
public class TestWidgets extends ActivityInstrumentationTestCase2<DummyActivityForTest> {
private AppCompatActivity mActivity;
public TestWidgets() {
super(DummyActivityForTest.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
}
@Test
public void testAddSpecializationClick() {
onView(withId(R.id.widgets_rv)).perform(
RecyclerViewActions.actionOnItemAtPosition(4, click()));
Assert.fail("Not Implemented");
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的测试类时,它抛出异常, …
android unit-testing android-espresso android-instrumentation
我想在CardView中创建一个TabLayout,如下所示:
TabView内的TabLayout
但坚持添加ViewPager适配器.
由于我使用RecyclerView,我将TabLayout和ViewPager放在myViewHolder中
public class MyViewHolder extends RecyclerView.ViewHolder {
TabLayout tabLayout;
public MyViewHolder(View itemView) {
super(itemView);
tabLayout = (TabLayout) itemView.findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("TAB 1"));
tabLayout.addTab(tabLayout.newTab().setText("TAB 2"));
tabLayout.addTab(tabLayout.newTab().setText("TAB 3"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) itemView.findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
但是我在getSupportFragmentManager上得到"无法解析方法".
这是PagerAdapter类.
public …
Run Code Online (Sandbox Code Playgroud) android android-fragments firebase android-cardview android-recyclerview
我进行了搜索,但没有找到适合我的情况的任何好的解决方案,即:我需要过滤List<Article>
通过分页库生成的现有内容,但无法弄清楚如何从FeedActivity的FeedDataSource类中的 api 请求中检索实际的articleList 。我需要在adapter.submitList(pagedList);之前过滤实际列表
FeedDataSurce 类
public class FeedDataSource extends PageKeyedDataSource<Long, Article>{
private static final String QUERY = "movies";
private static final String API_KEY = "079dac74a5f94ebdb990ecf61c8854b7";
private static final String TAG = FeedDataSource.class.getSimpleName();
private RestApi restApi;
private MutableLiveData networkState;
public FeedDataSource() {
restApi = RestApiFactory.feedRequest();
networkState = new MutableLiveData();
}
public MutableLiveData getNetworkState() {
return networkState;
}
@Override
public void loadInitial(@NonNull LoadInitialParams<Long> params,
@NonNull LoadInitialCallback<Long, Article> callback) {
networkState.postValue(NetworkState.LOADING);
restApi.fetchFeed(QUERY, API_KEY, 1, params.requestedLoadSize)
.enqueue(new …
Run Code Online (Sandbox Code Playgroud) 我正在尝试理解为什么适配器方法notifyDataSetChanged()无法刷新我的recyclerview。我在适配器这样的创建方法时找到了解决方案:
fun setData(list: List<DownloadModel>){
resumeList = list
notifyDataSetChanged()
}
Run Code Online (Sandbox Code Playgroud)
此解决方案有效,但是,我想知道为什么我不能做这样的事情:
private lateinit var downloadAdapter: DownloadRecyclerAdapter
private fun setupAdapter() {
downloadAdapter = DownloadRecyclerAdapter(
this@DownloadActivity,
downloadList,
{ id -> onViewClick(id) },
{ id -> onEditClick(id) },
{ id, position -> onDeleteClick(id, position) }
)
savedResumeRv.apply {
layoutManager = LinearLayoutManager(context)
layoutAnimation = AnimationUtils.loadLayoutAnimation(
this@DownloadActivity,
R.anim.layout_animation_down_to_up
)
adapter = downloadAdapter
}
}
private fun observers() {
downloadViewModel.getDownloadList().observe(this, Observer { list ->
downloadList = list
list?.let {
downloadAdapter.notifyDataSetChanged()
}
})
}
Run Code Online (Sandbox Code Playgroud)
downloadAdapter持有列表downloadList的相同实例,我不知道为什么当我在活动中通知适配器时无法正常工作。
以下是android代码片段
\n\nrunOnUiThread(new Runnable() {\n public void run() {\n AlertDialog alertDialog;\n alertDialog = new AlertDialog.Builder(MainActivity.this).create();\n alertDialog.setTitle("Network error");\n alertDialog.setMessage("Disconnected");\n alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "ok", new DialogInterface.OnClickListener() {\n /** ON clicking oKay button **/\n public void onClick(DialogInterface dialog, int id)\n {\n\n hasConnectServiceStarted = false;\n IP = null;\n// Intent intent = getIntent();\n Intent intentSplash = new Intent(getApplication().getApplicationContext(), SplashActivity.class);\n\n /** Shutdown the nodemain executor service if\n * HOST goes down\n */\n nodeMainExecutorService.forceShutdown();\n /** and restart the Main Activity that will prompt\n * user to reconnect to the …
Run Code Online (Sandbox Code Playgroud) 您好我正在尝试使用以下代码在特定位置获取recyclerview Viewholder:
val viewHolder = educationRv.findViewHolderForAdapterPosition(i) as SectionsRecyclerAdapter.ViewHolder
Run Code Online (Sandbox Code Playgroud)
问题是,回收站视图回收了不可见的物品,如果不可见,我将无法获得物品和位置0。我在询问是否尝试过此解决方案之前进行了搜索,但是无法阻止视图的回收(我知道这不是很好的解决方案,但是我被卡住了,无法更好地解决问题):
educationRv.recycledViewPool.setMaxRecycledViews(1,0)
override fun getItemViewType(position: Int): Int {
return 1
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
if (holder != null) {
holder.setIsRecyclable(false)
}
Run Code Online (Sandbox Code Playgroud)
通用->我有带有20个可动态添加的edittexts的recyclerview,当用户单击“保存”时,我需要获取所有edittexts值并将其保存到数组,单击按钮“ Save”时出现问题,当我尝试时仅可见两个或三个视图变得不可见返回null
我有清单:
var skillsList: MutableList<ComplexModel> = mutableListOf()
Run Code Online (Sandbox Code Playgroud)
ComplexModel 包含(名称、标题、开始日期、摘要)
我想找到更好的方法从SkillList创建新的 MutableList但新列表必须从第一个开始只获取 Name 和 Title。目前我正在使用这个解决方案,但我想知道是否有更好的方法来实现这一点。
val newArray: MutableList<SkillModel> = mutableListOf()
for (skill in skillsList) {
newArray.add(SkillModel(name = skill.name, title = skill.title))
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Android studio
并尝试创建一个使用Google Maps V2
. 我已经让地图运行良好API Key
。我将markers
在map
. 我想markers
以这样的方式添加:仅当它们位于radius
当前特定用户中时才会添加location
。有没有什么方法可以检查是否marker
进来radius
?我们如何radius
为地图添加 ?