我有一个ViewPager作为第一个项目RecyclerView.我想设置FragmentStatePagerAdapter到方法viewpager内部onBindViewHolder().但我不能打电话getsupportfragmentmanager().请帮助!! 这是我的代码:
public class CustomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private List<RowItem> rowItemList;
private final int VIEW_TYPE_CUSTOM = 0;
private final int VIEW_TYPE_NORMAL = 1;
NewPagerAdapter mCustomPagerAdapter;
public CustomListAdapter(Context context, List<RowItem> rowItemList) {
this.context = context;
this.rowItemList = rowItemList;
}
@Override
public int getItemViewType(int position) {
if (position == 0)
return VIEW_TYPE_CUSTOM;
else
return VIEW_TYPE_NORMAL;
}
@Override
public int getItemCount() {
return rowItemList.size()+1;
}
@Override
public void …Run Code Online (Sandbox Code Playgroud) 我有多个图像要在服务器上传,我有一个上传单个图像到服务器的方法.现在,我正在使用此方法通过为每个图像创建循环来发送多个图像.
有没有最快的方式将多个图像发送到服务器?提前致谢...
public int imageUpload(GroupInfoDO infoDO) {
ObjectMapper mapper = new ObjectMapper();
int groupId = 0;
try {
Bitmap bm = BitmapFactory.decodeFile(infoDO.getDpUrl());
String fileName = infoDO.getDpUrl().substring(
infoDO.getDpUrl().lastIndexOf('/') + 1,
infoDO.getDpUrl().length());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"http://192.168.1.24:8081/REST/groupreg/upload");
ByteArrayBody bab = new ByteArrayBody(data,
"application/octet-stream");
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploadFile", bab);
reqEntity.addPart("name", new StringBody(fileName));
reqEntity.addPart("grpId", new StringBody(infoDO.getGlobalAppId()
+ ""));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest); …Run Code Online (Sandbox Code Playgroud) 我有一个PhoneStateLister地方,我得到一堆数据,我发送到服务器.
如果我在片段中调用监听器,那一切都很好,但是当我在服务中调用它时,我得到了一个.这NullPointerException是我的代码:
PhoneStateListener:
public class CarrierStateListener extends PhoneStateListener {
private Context context;
private TelephonyManager telephonyManager;
private String carrierName;
private int mSignalStrength = 0;
private int mCellTowerID = 0;
private int mCellTowerAreCode = 0;
private int mcc = 0;
private int mnc = 0;
public CarrierStateListener(Context context) {
this.context = context;
}
/**
* Get the Signal strength from the provider, each time there is an update
*/
@Override
public void onSignalStrengthsChanged(final SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
telephonyManager …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些文本从我的Android应用程序共享给FB。没有登录功能,仅使用共享。
文本确实在FB上共享,但是即使取消共享,ShareDialog回调也始终返回onSuccess。
我正在使用以下代码:
//FB
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(contentTitle)
.setContentDescription(
message)
.setContentUrl(Uri.parse(contentUrl))
.build();
shareDialog = new ShareDialog(mActivity);
// this part is optional
shareDialog.registerCallback(MainActivity.callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Toast.makeText(mContext, R.string.yourpostsharedsuccessfully, Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
e.printStackTrace();
}
});
shareDialog.show(linkContent);
}
Run Code Online (Sandbox Code Playgroud)
并在我的活动中使用它:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
Run Code Online (Sandbox Code Playgroud)
请帮忙。我需要知道何时成功共享帖子以及何时取消该帖子。我正在使用FB sdk 4.1.0。
我真的陷入了我的应用程序中的这个问题,这会导致点击按钮后崩溃.
我有一个单独的"Comment"对象类(CommentLab类,在一个arrayList中保存注释),一个CommentListFragment,它有我的注释的listView,以及PostCommentFragment,用于在CommentLab中向arrayList添加新的注释.
我向我添加了一个OptionMenu CommentListFragment,当我点击optoinMenu中的New Comment项时,我希望它启动CommentListFragment类,我可以在其中编辑和添加新注释.
以下是协同工作的部分内容:
在CommentListFragment中:
// method to add an option menu to the fragment
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_comment_list, menu);
}
// method to indicate what to do when an item is selected on the menu(which,what)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menu_item_new_comment:
Comment comment = new Comment();
CommentLab.get(getActivity()).addComment(comment);
Intent i = new Intent(getActivity(), PostCommentActivity.class);
i.putExtra(PostCommentFragment.EXTRA_COMMENT, comment.getId());
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Run Code Online (Sandbox Code Playgroud)
PostCommentActivity(PostCommentFragment的托管活动):
public …Run Code Online (Sandbox Code Playgroud) 我想从DCIM目录中获取所有文件列表,但我不知道为什么,它不起作用.我正在使用下面的示例,但没有数据.
Environment.DIRECTORY_DCIM
Run Code Online (Sandbox Code Playgroud)
要么
Environment.getExternalStorageDirectory().getAbsolutePath()
Run Code Online (Sandbox Code Playgroud)
我也尝试了其他选择,但没办法.有人可以帮帮我吗?