小编Emi*_*ile的帖子

片段 getActivity() 中的 Android AlertDialog Builder 不起作用

我尝试在 Fragment 中构建 AlertDialog,但找不到 AlertDialog Builder 的正确上下文。

public class LoginFragment extends Fragment {
public LoginFragment() {
    // Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_login, container, false);

    Button btnEnter = (Button) rootView.findViewById(R.id.btnEnter);

    // Listening to register new account link
    btnEnter.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

        // if play name already exists
            AlertDialog dialog = new AlertDialog.Builder(getActivity())
                .setCancelable(false)
                .setIcon(R.drawable.login_icon)
                .setMessage("Player …
Run Code Online (Sandbox Code Playgroud)

android builder fragment android-alertdialog

1
推荐指数
1
解决办法
4694
查看次数

将超过 100 天的 S3 文件移动到另一个存储桶

有没有办法在一个 S3 存储桶中找到所有超过 100 天的文件并将它们移动到另一个存储桶?欢迎使用 AWS CLI 或 SDK 的解决方案。在 src 存储桶中,文件的组织方式类似于存储桶/类型/年/月/日/小时/文件
S3://my-logs-bucket/logtype/2020/04/30/16/logfile.csv
。例如, on 2020/04/302020/01/21必须移动或之前的日志文件。

amazon-s3 amazon-web-services aws-cli aws-sdk

1
推荐指数
1
解决办法
1921
查看次数

在Fragment Android中使用GoogleApiClient

我试图将Google地图加载到片段中.我不知道这三行应该是什么......(三行注释"问题!").

大多数例子在括号中使用"this".我知道这是一个片段,而不是一个活动,所以我用"getActivity()"代替.但是,如果我将所有三行更改为getActivity(),它也不起作用.请帮忙!提前致谢!

public class MapFragment extends Fragment implements OnMapReadyCallback,GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener,com.google.android.gms.location.LocationListener {
private static final String TAG = "***MapFragment***";
private final int PERMISSION_CODE = 1;
private GoogleApiClient myGoogleApiClient;
private GoogleMap myMap;
private Location curLocation;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_target, container, false);

// create api client
if (myGoogleApiClient == null) {
    myGoogleApiClient = new GoogleApiClient.Builder(getActivity())  // problem!
            .addConnectionCallbacks(this)   // problem! …
Run Code Online (Sandbox Code Playgroud)

google-maps fragment android-context google-api-client

-2
推荐指数
1
解决办法
3976
查看次数