我一直在为我的Android应用程序使用SwipeableRecyclerView来为我的recyclerView启用滑动.RecyclerView包含cardViews列表.
我试图为卡片实现撤消功能,当向左滑动时会被删除(第一次滑动显示撤消,下一次滑动触发器删除)
我正在尝试以下代码(部分工作,我猜)
SwipeableRecyclerViewTouchListener srvTouchListner = new SwipeableRecyclerViewTouchListener(rvTimerList,
new SwipeableRecyclerViewTouchListener.SwipeListener(){
@Override
public boolean canSwipe(int i) {
return true;
}
@Override
public void onDismissedBySwipeLeft(RecyclerView recyclerView, int[] ints) {
for(int position : ints){
View view = recyclerView.getChildAt(position);
if (view.getTag(R.string.card_undo) == null) {
if(viewStack == null) {
saveToViewStack(position, view);
final ViewGroup viewGroup = (ViewGroup) view.findViewById(R.id.time_card2);
view.setTag(R.string.card_undo, "true");
viewGroup.addView(view.inflate(TimerSummary.this, R.layout.timeslot_card_undo, null));
}
} else {
Log.d(TAG, "Removing Item");
deleteTimeSlot(timerInstanceList.get(position));
Toast.makeText(TimerSummary.this, "Deleted!", Toast.LENGTH_SHORT).show();
timerInstanceList.remove(position);
finalSummaryAdapter.notifyItemRemoved(position);
}
}
finalSummaryAdapter.notifyDataSetChanged();
}
@Override
public void onDismissedBySwipeRight(RecyclerView recyclerView, int[] …Run Code Online (Sandbox Code Playgroud) 我试图测试我在 android 中使用 jetpack compose 构建的 UI 并添加这些依赖项来设置它
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.1.0"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.0.5"
Run Code Online (Sandbox Code Playgroud)
为了测试我刚刚开始写以下内容
class LoginActivityComposeTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun socialPluginsTest() {
composeTestRule.setContent {
SocialLogins()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试导入的 createComposeRule() 不可用。我尝试手动导入import androidx.compose.ui.test.junit4.createComposeRule但是当我尝试运行测试后出现错误
Unresolved reference: junit4
这是我正在使用的完整 build.gradle 依赖项
compose_version ='1.0.1'retrofit_version ='2.9.0'
implementation "androidx.core:core-ktx:1.7.0"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
implementation "androidx.activity:activity-compose:1.4.0"
implementation "androidx.navigation:navigation-compose:2.5.0-alpha01"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0"
implementation 'com.google.android.gms:play-services-auth:20.1.0'
implementation "io.coil-kt:coil-compose:1.4.0"
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0" …Run Code Online (Sandbox Code Playgroud) 这是我的异常类。异常类已经由flutter的抽象异常类实现。我错过了什么吗?
class FetchDataException implements Exception {
final _message;
FetchDataException([this._message]);
String toString() {
if (_message == null) return "Exception";
return "Exception: $_message";
}
}
void loginUser(String email, String password) {
_data
.userLogin(email, password)
.then((user) => _view.onLoginComplete(user))
.catchError((onError) => {
print('error caught');
_view.onLoginError();
});
}
Future < User > userLogin(email, password) async {
Map body = {
'username': email,
'password': password
};
http.Response response = await http.post(apiUrl, body: body);
final responseBody = json.decode(response.body);
final statusCode = response.statusCode;
if (statusCode != HTTP_200_OK || …Run Code Online (Sandbox Code Playgroud) function myfunc( value1, value2='defaultValue' ) {
//some stuff
}
Run Code Online (Sandbox Code Playgroud)
如果参数传入或不传入函数,我怎么知道呢?我知道如果你没有传递任何东西作为参数,将设置默认值.我实际上想要检查用户是否作为第二个参数传递任何东西(即使它与默认值相同)并更改我的返回相应的价值.
谢谢,