1
我已經創建了一個帶有一些視圖組件的片段。我只需要從該組件中僅掃描圖像,但是我的代碼完整片段正在交換。我怎樣才能交換碎片的圖像 貝婁是我的代碼。我已經使用ViewPager做刷卡片段只掃描來自片段的圖像不完整片段
public class DetailedSwiperImageAdapter extends PagerAdapter {
private Context mContext;
FoodDetail foodDetails;
private List<FoodDetail> foodDetailsList = new ArrayList<>();
private final int currentPosition;
public DetailedSwiperImageAdapter(Context fragmentContext, List<FoodDetail> foodDetail, int position) {
mContext = fragmentContext;
foodDetailsList = foodDetail;
currentPosition = position;
}
@Override
public int getCount() {
return foodDetailsList.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.detailed_fragment, container,
false);
foodDetails = foodDetailsList.get(position);
View view = populateDataForDetailedLayout(viewLayout, foodDetails);
container.addView(view);
return view;
}
/*
* fetch the data from the timeline and display it in the detailed screen
*/
private View populateDataForDetailedLayout(View viewLayout, FoodDetail foodDetails) {
((TextView) viewLayout.findViewById(R.id.detailed_meal_type)).setText(foodDetails.getFoodType().name());
ImageView dishImageView = (ImageView) viewLayout.findViewById(R.id.dish_image_view);
File imgFile = new File(foodDetails.getFoodImageLocalPath());
if (imgFile.exists()) {
dishImageView.setImageURI(Uri.fromFile(imgFile));
}
final TextView detaileMessage = (TextView) viewLayout.findViewById(R.id.detaile_message);
TextView detaileLocation = (TextView) viewLayout.findViewById(R.id.detaile_location);
TextView detaileDishName = (TextView) viewLayout.findViewById(R.id.detaile_dish_name);
TextView detaileTime = (TextView) viewLayout.findViewById(R.id.detaile_time);
ImageView emojiImage = (ImageView) viewLayout.findViewById(R.id.emoji_detailed);
detaileDishName.setText(foodDetails.getFoodName());
String smrtMsg = foodDetails.getSmartmessage();
if (smrtMsg != null) {
smrtMsg = smrtMsg.replaceAll("[\n\r]", "");
detaileMessage.setText(smrtMsg);
}
if (foodDetails.getIntentEmojiUnicode() != null) {
Picasso.with(mContext).load(RemoteUtils.getIntentImageURIString(foodDetails.getIntentEmojiUnicode(), null, "khanapal")).into(emojiImage);
}
CharSequence time = DateUtils.getRelativeDateTimeString(mContext,
foodDetails.getStartTime().getTime(), DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
detaileTime.setText(time);
String location = "";
if (!TextUtils.isEmpty(foodDetails.getStreet())) {
location = foodDetails.getStreet();
} else if (!TextUtils.isEmpty(foodDetails.getLocationName())) {
location = foodDetails.getLocationName();
} else if (!TextUtils.isEmpty(foodDetails.getCity())) {
location = foodDetails.getCity();
} else if (!TextUtils.isEmpty(foodDetails.getCountry())) {
location = foodDetails.getCountry();
}
location += " - " + foodDetails.getLocationUnformattedAddress() + "";
if (foodDetails.getLocationUnformattedAddress() == null) location = "No location";
detaileLocation.setText(location);
//used for message edting on click of smart message text editor
detaileMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = detaileMessage.getText().toString();
editMessage(message, detaileMessage);
}
});
return viewLayout;
}
}