我不知道如何将图像放入AlertDialog.
我有这个代码,但我认为这是不可能的.
AlertDialog.Builder alert = new AlertDialog.Builder(MessageDemo.this);
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageResource(R.drawable.cw);
alert.setView(imageView);
alert.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}
});
alert.show();
Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用RxJava2,Kotlin-1.1和RxBindings.
我有一个简单的登录界面,默认情况下禁用"登录"按钮,我想只在用户名和密码的edittext字段不为空时启用该按钮.
LoginActivity.java
Observable<Boolean> isFormEnabled =
Observable.combineLatest(mUserNameObservable, mPasswordObservable,
(userName, password) -> userName.length() > 0 && password.length() > 0)
.distinctUntilChanged();
Run Code Online (Sandbox Code Playgroud)
我无法将上述代码从Java翻译成Kotlin:
LoginActivity.kt
class LoginActivity : AppCompatActivity() {
val disposable = CompositeDisposable()
private var userNameObservable: Observable<CharSequence>? = null
private var passwordObservable: Observable<CharSequence>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
initialize()
}
fun initialize() {
userNameObservable = RxTextView.textChanges(username).skip(1)
.debounce(500, TimeUnit.MILLISECONDS)
passwordObservable = RxTextView.textChanges(password).skip(1)
.debounce(500, TimeUnit.MILLISECONDS)
}
private fun setSignInButtonEnableListener() {
val isSignInEnabled: Observable<Boolean> = Observable.combineLatest(userNameObservable,
passwordObservable,
{ u: CharSequence, p: CharSequence …Run Code Online (Sandbox Code Playgroud) 我想知道RealmResults和之间有什么区别RealmList.
我看到的唯一区别是realmlist是输入数据,而RealmResults是运行查询.
谢谢
我在活动中定义了一个searchview,如下所示:
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
public class SearchActivity extends AppCompatActivity {
@BindView(R.id.search_view) SearchView searchView;
private void setupSearchView() {
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconified(false);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override public boolean onQueryTextSubmit(String s) {
searchView.clearFocus();
return true;
}
@Override public boolean onQueryTextChange(String s) {
searchFor(s);
return true;
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
的build.gradle
androidBuildToolsVersion = "25.0.2"
androidMinSdkVersion = 16
androidTargetSdkVersion = 25
androidCompileSdkVersion = 25
supportVersion = '25.1.0'
Run Code Online (Sandbox Code Playgroud)
在分析(分析 - >检查代码)时,lint工具报告以下问题:
SearchView.clearFocus只能在同一个库组中调用(groupId = com.android.support)
我不确定我做错了什么,有人能为我提供解决方案吗?
我在前端使用react-apollo,在后端使用graphcool.我有一个突变,创建一个这样的教程:
const CREATE_TUTORIAL_MUTATION = gql`
mutation CreateTutorialMutation(
$author: String
$link: String
$title: String!
$postedById: ID!
$completed: Boolean!
) {
createTutorial(
author: $author
link: $link
title: $title
postedById: $postedById
completed: $completed
) {
author
link
title
postedBy {
id
name
}
completed
}
}
`
Run Code Online (Sandbox Code Playgroud)
它在提交处理程序中调用,如此...
this.props.createTutorialMutation({
variables: {
author,
link,
title,
completed: false,
postedById
}
})
Run Code Online (Sandbox Code Playgroud)
一切都很美妙.
现在我想在创建新教程时添加一组标记.我创建了输入字段并将其连接起来,以便tags变量是一个对象数组,每个对象都有一个标记id和标记文本.
如果我尝试将标记字段添加到变异中,则需要标量类型.但是对于一组对象似乎没有标量类型.
如果我在调用变异时将tag变量作为参数传递,我如何填充变异中的Scalar类型字段(在148行上这里https://github.com/joshpitzalis/path/blob/graphQL/src/ components/Add.js)和架构?
我是graphQL的新手,我明白我可能会以错误的方式接近这一点.如果是这种情况,我如何在graphQL中添加一个对象数组?
我使用的是Retrofit同RxJava为网络电话和RxBinding用于查看操作.在注册屏幕中,单击"注册"按钮后,我将使用该MyApi服务将信息发布到本地服务器.
SignupActivity.class
mCompositeSubscription.add(RxView.clicks(mRegisterButton).debounce(300, TimeUnit.MILLISECONDS).
subscribe(view -> {
registerUser();
}, e -> {
Timber.e(e, "RxView ");
onRegistrationFailed(e.getMessage());
}));
private void registerUser() {
mCompositeSubscription.add(api.registerUser(mEmail,
mPassword, mConfirmPassword)
.subscribe(user -> {
Timber.d("Received user object. Id: " + user.getUserId());
}, e -> {
Timber.e(e, "registerUser() ");
onRegistrationFailed(e.getMessage());
}));
}
Run Code Online (Sandbox Code Playgroud)
MyApi.class
public Observable<User> registerUser(String username, String password, String confirmPassword) {
return mService.registerUser(username, password, confirmPassword)
.compose(applySchedulers());
}
@SuppressWarnings("unchecked") <T> Observable.Transformer<T, T> applySchedulers() {
return observable -> observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
} …Run Code Online (Sandbox Code Playgroud) 我有一个首选项 util 类可以在一个地方存储和检索共享首选项中的数据。
Prefuutils.java:
public class PrefUtils {
private static final String PREF_ORGANIZATION = "organization";
private static SharedPreferences getPrefs(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context);
}
private static SharedPreferences.Editor getEditor(Context context) {
return getPrefs(context).edit();
}
public static void storeOrganization(@NonNull Context context,
@NonNull Organization organization) {
String json = new Gson().toJson(organization);
getEditor(context).putString(PREF_ORGANIZATION, json).apply();
}
@Nullable public static Organization getOrganization(@NonNull Context context) {
String json = getPrefs(context).getString(PREF_ORGANIZATION, null);
return new Gson().fromJson(json, Organization.class);
}
}
Run Code Online (Sandbox Code Playgroud)
显示 LoginActivity.java 中 PrefUtils 用法的示例代码:
@Override public void showLoginView() …Run Code Online (Sandbox Code Playgroud) android mockito sharedpreferences android-testing android-espresso
我试图做一个散点图,我的x轴需要是一年中的每一天.我首先在数据文件中读取并获取日期列,其中填充了整数,如19800801.所以我将其转换integer为datetime:
datetimes_0 = datetime.strptime(str(dates_pitts[0]), '%Y%m%d')
Run Code Online (Sandbox Code Playgroud)
然后我想通过编写以下内容从datetime对象中仅提取月份和日期:
s = datetimes_0.strftime("%m%d")
Run Code Online (Sandbox Code Playgroud)
我意识到他们返回的值strftime不再是日期时间对象,所以我尝试将其转换回datetime对象
s0= datetime.strptime(s, '%m%d')
Run Code Online (Sandbox Code Playgroud)
但它不是只给我一个月和一天,而是让我回到了整年,一个月和一天.我的问题是如何从给定的整数(如19800801)中提取只有月和日(两者)的日期时间对象?
我有一个示例API请求,它返回用户监视列表的列表.我想在用户加载监视列表屏幕时实现以下流程:
立即从DB缓存加载数据.(cacheWatchList)
在后台启动RetroFit网络呼叫.
一世.onSuccess返回apiWatchList
ii.onError返回cacheWatchList
Diff cacheWatchListvs.apiWatchList
一世.相同 - >一切都很好,因为数据已经显示给用户什么都不做.
II.不同 - >保存apiWatchList到本地商店并发apiWatchList送到下游.
到目前为止我做了什么?
Watchlist.kt
data class Watchlist(
val items: List<Repository> = emptyList()
)
Run Code Online (Sandbox Code Playgroud)
LocalStore.kt(Android室)
fun saveUserWatchlist(repositories: List<Repository>): Completable {
return Completable.fromCallable {
watchlistDao.saveAllUserWatchlist(*repositories.toTypedArray())
}
}
Run Code Online (Sandbox Code Playgroud)
RemoteStore.kt(改造api调用)
fun getWatchlist(userId: UUID): Single<Watchlist?> {
return api.getWatchlist(userId)
}
Run Code Online (Sandbox Code Playgroud)
DataManager.kt
fun getWatchlist(userId: UUID): Flowable<List<Repository>?> {
val localSource: Single<List<Repository>?> =
localStore.getUserWatchlist()
.subscribeOn(scheduler.computation)
val remoteSource: Single<List<Repository>> …Run Code Online (Sandbox Code Playgroud) 我的didSelectItemAt方法没有被调用,也没有任何东西被打印到控制台中。我打开了用户交互,但仍然无法打印出任何内容。我不确定是我的自定义 PinterestStyle 布局导致了这个还是我遗漏了什么。最终目标是进入显示所选单元格的配置文件页面的详细视图控制器。我会使用prepareForSegue但是我仍然无法让它在点击时打印出单元格的名称。
class PagesCollectionViewController: UICollectionViewController, firebaseHelperDelegate {
var storageRef: StorageReference!{
return Storage.storage().reference()
}
var usersList = [String]()
var authService : FirebaseHelper!
var userArray : [Users] = []
var images: [UIImage] = []
var names: [String] = []
override func viewWillAppear(_ animated: Bool) {
if Global.Location != "" && Global.Location != nil
{
usersList = Global.usersListSent
print(usersList)
self.authService.ListOfUserByLocation(locationName: Global.Location, type: .ListByLocation)
}
}
override func viewDidLoad() {
self.collectionView?.allowsSelection = true
self.collectionView?.isUserInteractionEnabled = true
super.viewDidLoad()
self.authService = …Run Code Online (Sandbox Code Playgroud)