我需要使用Robolectric在Android应用程序中编写测试菜单.
菜单源代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.exit:
this.finish();
break;
default:
Toast.makeText(this, getString(R.string.errMsg), Toast.LENGTH_SHORT).show();
break;
}
return super.onMenuItemSelected(featureId, item);
}
Run Code Online (Sandbox Code Playgroud)
请帮忙写测试
我们正在开发用于订购食品的应用程序。在这种情况下,我们实施了 Braintree 支付。一切都很好。下一步是实施 Google Pay(我注意了,不是 Android Pay)。我使用了这个文档:Braintree Docs:https : //developers.braintreepayments.com/guides/pay-with-google/configuration/android/v2
谷歌 PwG 文档:https : //developers.google.com/payments/setup
这是我们如何实施 Google Pay:
private GooglePaymentRequest getGooglePaymentRequest(String total) {
return new GooglePaymentRequest()
.transactionInfo(TransactionInfo.newBuilder()
.setTotalPrice(total)
.setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
.setCurrencyCode("AUD")
.build())
.emailRequired(false)
.shippingAddressRequired(false)
.phoneNumberRequired(false)
.allowPrepaidCards(true)
.billingAddressRequired(false);
}
Run Code Online (Sandbox Code Playgroud)
并使用:
String total = String.format(Locale.getDefault(), "%1$.2f", basket.total);
DropInRequest dropInRequest = new DropInRequest()
.clientToken(clientToken)
.amount(total)
.googlePaymentRequest(getGooglePaymentRequest(total))
.collectDeviceData(true);
getMvpView().showBraintreePaymentScreen(dropInRequest);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们有两种情况:在我同事的设备上一切正常(视频:https : //drive.google.com/open?id=1wEXbv8qzGXzuXWDUy7-bhIdud_4H_s2V)
在我这边,我崩溃了(视频:https : //drive.google.com/open?id=15gvtkNGZ9w6v1ym7cDkwWCnqHh5JUvL7)
正如你在 Braintree 的 BaseActivity 中看到的,我得到了 statusCode=10 的异常,这意味着 DEVELOPER_ERROR。
那么有没有人想过如何修复它?
我在装载机上遇到了一些麻烦,但是我不明白我做错了什么。这是初始化并启动Loader的片段
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.pixelark.bulletinplus.R;
import com.pixelark.bulletinplus.async.ChurchListLoader;
import com.pixelark.bulletinplus.debug.Debug;
import com.pixelark.bulletinplus.model.ChurchListItem;
import java.util.ArrayList;
public class ChurchListFragment extends android.support.v4.app.Fragment
implements LoaderManager.LoaderCallbacks<ArrayList<ChurchListItem>> {
private static final int CHURCH_LIST_LOADER_ID = 777;
public ChurchListFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_church_list, container, false);
Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("ChurchListFragment");
getLoaderManager().initLoader(CHURCH_LIST_LOADER_ID, null, this);
return rootView;
}
@Override
public Loader<ArrayList<ChurchListItem>> …
Run Code Online (Sandbox Code Playgroud) 我需要做这样的事情:
这是 10 个圆形视图,其宽度相同,具体取决于父级宽度。
我现在拥有的:
Column(
modifier = Modifier
.fillMaxWidth()
.background(color = Color.White)
.padding(vertical = 12.dp)
) {
Row(
modifier = Modifier
.padding(horizontal = 20.dp)
.padding(top = 12.dp)
) {
for (i in 1..10) {
Surface(
shape = CircleShape,
modifier = Modifier
.padding(horizontal = 2.dp)
.width(0.dp)
.height(29.dp)
.weight(1F)
.clip(CircleShape),
color = surfaceColor,
onClick = { selected = i },
) {
Text(
modifier = Modifier
.fillMaxWidth()
.wrapContentSize(Alignment.Center),
text = "$i",
color = textColor,
style = subtitle1(),
overflow = TextOverflow.Ellipsis,
) …
Run Code Online (Sandbox Code Playgroud)