2016-07-23 65 views
1

我在main_activity中創建了一個Recyclerview,我想在部分活動中使用此Cardview ...我將附加變量和數據放到新活動中,但是沒有在新活動中顯示任何東西。 ..CardView沒有顯示任何錯誤的內容

這是我的部分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"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_view1" 
     android:layout_width="match_parent" 
     android:layout_height="288dp" 
     android:layout_margin="@dimen/card_margin" 
     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"> 

     </RelativeLayout> 

    </android.support.v7.widget.CardView> 

    <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" /> 

    <ImageView 
     android:id="@+id/thumbnail1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/selectableItemBackgroundBorderless" 
     android:clickable="true" 
     android:scaleType="fitXY" 
     android:contextClickable="true" 
     android:layout_alignTop="@+id/title1" /> 

    <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" /> 

</LinearLayout> 

這是我的HotelPageList.java:

package ir.homa; 
public class HotelPageList { 
    private String name; 
    private int numOfRooms; 
    private int thumbnail; 


    public HotelPageList() { 
    } 

    public HotelPageList(String name, int numOfRooms, int thumbnail) { 
     this.name = name; 
     this.numOfRooms = numOfRooms; 
     this.thumbnail = thumbnail; 

    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public int getNumOfRooms() { 
     return numOfRooms; 
    } 

    public void setNumOfRooms(int numOfRooms) { 
     this.numOfRooms = numOfRooms; 
    } 

    public int getThumbnail() { 
     return thumbnail; 
    } 

    public void setThumbnail(int thumbnail) { 
     this.thumbnail = thumbnail; 
    } 


} 

這是HotelPageAdapter.java:

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.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, overflow1; 

     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); 
      overflow1 = (ImageView) view.findViewById(R.id.overflow); 
     } 
    } 
    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) { 



     final HotelPageList hotel = hotelPage.get(position); 
     holder.title1.setText(hotel.getName()); 
     holder.count1.setText(hotel.getNumOfRooms() + " اتاق"); 

     // loading hotel cover using Glide library 
     Glide.with(mContext).load(hotel.getThumbnail()).into(holder.thumbnail1); 

    } 


    @Override 
    public int getItemCount() {return hotelPage.size();} 
} 

,這是結果:

enter image description here

在哪裏的問題?

+0

您確定您的語言完全支持默認文本視圖嗎?嘗試一些英文的虛擬數據,以確保 –

回答

0
Try this way 

<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:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/imageView2" 
        android:src="@drawable/ic_launcher" 
        android:layout_centerVertical="true" 
        android:layout_centerHorizontal="true" /> 
      </RelativeLayout> 

     </android.support.v7.widget.CardView> 

    </LinearLayout> 
    <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:text="Title" 
     android:layout_above="@+id/count1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="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_launcher" 
     android:contextClickable="true" 
     android:layout_alignTop="@+id/title1" /> 

    <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:text="sub title" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

</LinearLayout> 
+0

我沒有看到任何改變!... – Mohammadreza

+0

你現在得到什麼錯誤? – param

+0

沒什麼......我試圖在textview和imgview中顯示我的字段值 – Mohammadreza