I've transferred my data to new activity -> from HotelListAdapter.java to HotelPage.java
I set Log to be sure the Data have been transferred successfully. Log is working now and show my variables value , but my TextView and ImageView do not display my data (Or variables )...
this is my LogCat:
07-25 20:57:33.214 4041-4041/ir.homa I/LOG: 2130903040
07-25 20:57:33.214 4041-4041/ir.homa I/LOG: هما - بندرعباس
07-25 20:57:33.214 4041-4041/ir.homa I/LOG: 187
07-25 20:57:33.214 4041-4041/ir.homa I/LOG: 0
this is my HotelListAdapter.java :
package ir.homa;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.util.List;
/**
* Created by SMQ on 7/3/2016.
*/
public class HotelListAdapter extends RecyclerView.Adapter<HotelListAdapter.MyViewHolder> {
private Context mContext;
private List<HotelList> hotelList;
private List<HotelPageList> hotelPage;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title, count;
public ImageView thumbnail, overflow;
public RelativeLayout card;
public MyViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.title);
count = (TextView) view.findViewById(R.id.count);
thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
overflow = (ImageView) view.findViewById(R.id.overflow);
card = (RelativeLayout) view.findViewById(R.id.card);
}
}
public HotelListAdapter(Context mContext, List<HotelList> hotelList) {
this.mContext = mContext;
this.hotelList = hotelList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.hotel_list, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
final HotelList hotel = hotelList.get(position);
holder.title.setText(hotel.getName());
holder.count.setText(hotel.getNumOfRooms() + " اتاق");
// loading hotel cover using Glide library
Glide.with(mContext).load(hotel.getThumbnail()).into(holder.thumbnail);
holder.overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPopupMenu(holder.overflow);
}
});
holder.thumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int thumbnail1 = hotel.getThumbnail();
String name1 = hotel.getName();
int count1 = hotel.getNumOfRooms();
int position1 = holder.getAdapterPosition();
switch(holder.getAdapterPosition()) {
case 0:
Intent intent = new Intent(mContext,HotelPage.class);
intent.putExtra("position1", position1);
intent.putExtra("thumbnail", thumbnail1);
intent.putExtra("name", name1);
intent.putExtra("count", count1);
mContext.startActivity(intent);
break;
case 1:
Intent intent2 = new Intent(mContext, HotelPage.class);
intent2.putExtra("position1", position1);
mContext.startActivity(intent2);
break;
}
}
});
}
/**
* run intent filter when user clicked on each thumbnails!
*/
// Create an anonymous implementation of OnClickListener
/**
* Showing popup menu when tapping on 3 dots
*/
private void showPopupMenu(View view) {
// inflate menu
PopupMenu popup = new PopupMenu(mContext, view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.hotel_list_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
popup.show();
}
class MyMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {
public MyMenuItemClickListener() {
}
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_add_favourite:
Toast.makeText(mContext, "به علاقه مندی ها افزوده شد!", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_hotel_next:
Toast.makeText(mContext, "بزودی در دسترس قرار میگیرد!", Toast.LENGTH_SHORT).show();
return true;
default:
}
return false;
}
}
@Override
public int getItemCount() {
return hotelList.size();
}
}
this is my HotelPageAdapter:
package ir.homa;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.List;
/**
* Created by SMQ on 7/20/2016.
*/
public class HotelPageAdapter extends RecyclerView.Adapter<HotelPageAdapter.MyViewHolder> {
private Context mContext;
private List<HotelPageList> hotelPage;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title1, count1;
public ImageView thumbnail1;
public RelativeLayout card;
public MyViewHolder(View view) {
super(view);
title1 = (TextView) view.findViewById(R.id.title1);
count1 = (TextView) view.findViewById(R.id.count1);
thumbnail1 = (ImageView) view.findViewById(R.id.thumbnail1);
card = (RelativeLayout) view.findViewById(R.id.card);
}
}
public HotelPageAdapter(Context mContext, List<HotelPageList> hotelPage) {
this.mContext = mContext;
this.hotelPage = hotelPage;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.hotel_page, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
HotelPage GetExtras = new HotelPage();
final HotelPageList hotel = hotelPage.get(position);
holder.title1.setText(GetExtras.name);
holder.count1.setText(GetExtras.count + " اتاق");
// loading hotel cover using Glide library
Glide.with(mContext).load(hotel.getThumbnail()).into(holder.thumbnail1);
}
@Override
public int getItemCount() {return hotelPage.size();}
}
this is HotelPage.java:
package ir.homa;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import java.util.List;
/**
* Created by SMQ on 7/17/2016.
*/
public class HotelPage extends Activity {
private Context mContext;
private RecyclerView recyclerView;
private HotelPageAdapter adapter;
private List<HotelPageList> hotelPage;
private List<HotelList> hotelList;
private View view;
public String name;
public int count;
public int thumbnail;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hotel_page);
hotelPage = new ArrayList<>();
adapter = new HotelPageAdapter(this, hotelPage);
prepareHotels();
try {
Glide.with(this).load(R.color.bg_main).into((ImageView) findViewById(R.id.backdrop));
} catch (Exception e) {
e.printStackTrace();
}
}
private int dpToPx(int dp) {
Resources r = getResources();
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()));
}
private void prepareHotels() {
final HotelPageList hotel = new HotelPageList();
Bundle extras = getIntent().getExtras();
name = extras.getString("name");
count = extras.getInt("count");
thumbnail = extras.getInt("thumbnail");
Log.i("LOG", String.valueOf(thumbnail));
Log.i("LOG", name);
Log.i("LOG", String.valueOf(count));
Log.i("LOG", String.valueOf(hotel.position1));
HotelPageList b = new HotelPageList( name , count, thumbnail);
hotelPage.add(b);
adapter.notifyDataSetChanged();
}
// Create an anonymous implementation of OnClickListener
/**
* RecyclerView item decoration - give equal margin around grid item
*/
public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
private int spanCount;
private int spacing;
private boolean includeEdge;
public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
this.spanCount = spanCount;
this.spacing = spacing;
this.includeEdge = includeEdge;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view); // item position
int column = position % spanCount; // item column
if (includeEdge) {
outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)
if (position < spanCount) { // top edge
outRect.top = spacing;
}
outRect.bottom = spacing; // item bottom
} else {
outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing)
if (position >= spanCount) {
outRect.top = spacing; // item top
}
}
}
}
}
this is my XML (hotel_page.xml) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="288dp">
<android.support.v7.widget.CardView
android:id="@+id/card_view1"
android:layout_width="match_parent"
android:layout_height="288dp"
android:elevation="3dp"
card_view:cardCornerRadius="0dp"
android:gravity="top">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/card"
android:focusable="true"
android:contextClickable="true"
android:gravity="top"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/thumbnail1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:src="@drawable/ic_menu_send"
android:contextClickable="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/title1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="25dp"
android:paddingTop="10dp"
android:textColor="@color/cardview_dark_background"
android:textSize="15dp"
android:layout_above="@+id/count1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/count1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="25dp"
android:textSize="12dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
Please A REAL EXPERT answer to this hardship question...! <3