gpt4 book ai didi

java - CardView 由于任何错误而未显示内容

转载 作者:太空宇宙 更新时间:2023-11-04 12:24:09 24 4
gpt4 key购买 nike

我在 main_activity 中创建了一个 Recyclerview,我想在部分 Activity 中使用此卡片 View ...我将额外的变量和数据添加到新 Activity 中,但新 Activity 中未显示任何内容...

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

问题出在哪里?

最佳答案

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>

关于java - CardView 由于任何错误而未显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38539931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com