- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
构建电影应用程序,迷失在为什么当另一个以相同方式实现并工作时此回收器 View 不会显示任何内容的逻辑中。
确实有一个错误,就是找不到它。一直看着屏幕很长时间。提前致谢!!
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
tools:context="com.example.mrmohammad.movies4u.DetailActivity"
>
<LinearLayout
android:id="@+id/ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:showIn="@layout/activity_detail">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/tv_title_movie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="@dimen/tv_title_movie_margin_top_content_detail"
android:background="@drawable/bg_rating"
android:padding="@dimen/tv_title_movie_padding_content_detail"
android:text="Harry Potter"
android:textColor="#fff"
android:textSize="21sp"
android:textStyle="bold"
app:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_creator="1"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_release_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="@dimen/tv_release_year_content_detail_rating"
android:background="@drawable/bg_rating"
android:padding="@dimen/tv_title_movie_padding_content_detail"
android:text="2018"
android:textColor="#fff"
android:textSize="16sp"
app:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_creator="1"
app:layout_constraintTop_toBottomOf="@id/tv_title_movie" />
<TextView
android:id="@+id/tv_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="@dimen/tv_release_year_content_detail_rating"
android:background="@drawable/bg_rating"
android:drawableLeft="@drawable/ic_star_black_24dp"
android:padding="@dimen/tv_title_movie_padding_content_detail"
android:paddingRight="5dp"
android:text="8.9"
android:textColor="#fff"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_release_year" />
<RelativeLayout
android:id="@+id/llsynopsisbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="@dimen/tv_release_year_content_detail_rating"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_rating">
<TextView
android:id="@+id/tv_synopsis_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_rating"
android:padding="@dimen/tv_title_movie_padding_content_detail"
android:text="@string/synopsis"
android:textColor="#fff"
android:textSize="18sp" />
<View
android:id="@+id/emptyView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_toRightOf="@id/tv_synopsis_label"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="end"
android:orientation="horizontal">
<ImageView
android:id="@+id/share"
android:layout_width="35dp"
android:layout_height="35dp"
android:contentDescription="Share..."
android:padding="4dp"
android:src="@drawable/ic_share_black_24dp" />
<ImageView
android:id="@+id/saveFav"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_below="@id/share"
android:contentDescription="Save in Favorites"
android:padding="4dp"
android:src="@drawable/thumbsup" />
<ImageView
android:id="@+id/deleteFav"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_toRightOf="@id/saveFav"
android:contentDescription="Delete from Favorites"
android:padding="4dp"
android:src="@drawable/delete" />
</LinearLayout>
</RelativeLayout>
<TextView
android:id="@+id/tv_synopsis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/synopsis_margin_left"
android:layout_marginRight="@dimen/synopsis_margin_right"
android:layout_marginTop="@dimen/synopsis_margin_top"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitationlaboris nisi ut aliquip ex ea commodo consequat."
android:textColor="#fff"
android:textSize="15sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/llsynopsisbtn" />
<TextView
android:id="@+id/thumbnailURL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible" />
<LinearLayout
android:id="@+id/linLayContentDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_synopsis">
<TextView
android:id="@+id/trailer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/bg_rating"
android:padding="8dp"
android:text="Trailers"
android:textColor="#fff"
android:textSize="20sp"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvTrailers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:clipToPadding="false"
android:padding="12dp"
android:paddingBottom="25dp"
android:scrollbars="vertical"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/linLayContentDetail">
<TextView
android:id="@+id/review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/bg_rating"
android:padding="8dp"
android:text="Reviews"
android:textColor="#fff"
android:textSize="20sp"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:clipToPadding="false"
android:padding="12dp"
android:paddingBottom="25dp"
>
<!--HERE IS TEH RECYCLERVIEW THAT DONT DISPLAY-->
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
详细 Activity :
public class DetailActivity extends AppCompatActivity {
TextView movieName, releaseDate, userRating, synopsis;
int id;
ImageView iv, share, saveFav, deletFav;
private RecyclerView rvDetail, rvReview;
private TrailerAdapter adapter;
private ReviewAdapter reviewAdapter;
private List<Trailer> trailerList;
private List<Review> reviewList;
public static final String BASE_URL =
"https://image.tmdb.org/t/p/w500";
public static final String TAG = DetailActivity.class.getSimpleName();
public MovieDbHelper dbHelper;
private Movie favoriteMovie;
private AppCompatActivity activity = DetailActivity.this;
String poster, overview, rating, movieTitle, release;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Stetho.initializeWithDefaults(this);
share = findViewById(R.id.share);
saveFav = findViewById(R.id.saveFav);
deletFav = findViewById(R.id.deleteFav);
final int movie_id = getIntent().getExtras().getInt("id");
if (checkFavoriteMovie(movie_id)) {
//Is a favorite
saveFav.setVisibility(View.GONE);
saveFav.setEnabled(false);
deletFav.setEnabled(true);
deletFav.setVisibility(View.VISIBLE);
} else {
deletFav.setVisibility(View.GONE);
deletFav.setEnabled(false);
saveFav.setEnabled(true);
saveFav.setVisibility(View.VISIBLE);
}
iv = findViewById(R.id.iv_detail);
movieName = findViewById(R.id.tv_title_movie);
releaseDate = findViewById(R.id.tv_release_year);
userRating = findViewById(R.id.tv_rating);
synopsis = findViewById(R.id.tv_synopsis);
Intent intentFromAdapter = getIntent();
if (intentFromAdapter.hasExtra("original_title")) {
poster =
intentFromAdapter.getExtras().getString("poster_path");
movieTitle =
intentFromAdapter.getExtras().getString("original_title");
overview = intentFromAdapter.getExtras().getString("overview");
rating =
intentFromAdapter.getExtras().getString("vote_average");
release =
intentFromAdapter.getExtras().getString("release_date");
Picasso.with(this).load(BASE_URL + poster).into(iv);
movieName.setText(movieTitle);
releaseDate.setText(release);
userRating.setText(rating);
synopsis.setText(overview);
} else {
Toast.makeText(this, "No Data...", Toast.LENGTH_SHORT).show();
}
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(this);
saveFav.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkFavoriteMovie(movie_id)) {
Toast.makeText(activity, "Already added!",
Toast.LENGTH_SHORT).show();
} else {
SharedPreferences.Editor editor =
getSharedPreferences("com.example.mrmohammad.movies4u.DetailActivity", MODE_PRIVATE).edit();
editor.putBoolean("Favorite Added", true);
editor.commit();
addFavorites();
Toast.makeText(DetailActivity.this, "Movie Added successfully...", Toast.LENGTH_SHORT).show();
}
//
saveFav.setEnabled(false);
deletFav.setEnabled(true);
deletFav.setVisibility(View.VISIBLE);
saveFav.setVisibility(View.GONE);
//
}
});
deletFav.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = getSharedPreferences("com.example.mrmohammad.movies4u.DetailActivity", MODE_PRIVATE).edit();
editor.putBoolean("Favorite Removed", true);
editor.commit();
removeFromFavorites(movie_id);
Toast.makeText(DetailActivity.this, "Movie Removed...", Toast.LENGTH_SHORT).show();
//
deletFav.setEnabled(false);
saveFav.setEnabled(true);
deletFav.setVisibility(View.GONE);
saveFav.setVisibility(View.VISIBLE);
//
}
});
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String d = movieName.getText().toString().trim();
String s = "http://www.youtube.com/watch?v=" + d;
s = s.replaceAll(" ", "%20");
String full = "CLICK LINK " + s;
Intent shareIntent = ShareCompat.IntentBuilder.from(DetailActivity.this)
.setType("text/plain")
.setText(full)
.getIntent();
startActivity(shareIntent);
}
});
initializeViews();
}
private void initializeViews() {
/////// Trailers
trailerList = new ArrayList<>();
adapter = new TrailerAdapter(this, trailerList);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
rvDetail = findViewById(R.id.rvTrailers);
rvDetail.setLayoutManager(layoutManager);
rvDetail.setAdapter(adapter);
adapter.notifyDataSetChanged();
////////// Reviews
reviewList = new ArrayList<>();
reviewAdapter = new ReviewAdapter(this, reviewList);
RecyclerView.LayoutManager lm = new LinearLayoutManager(getApplicationContext());
rvReview = findViewById(R.id.rvReview);
rvReview.setLayoutManager(lm);
rvReview.setAdapter(reviewAdapter);
reviewAdapter.notifyDataSetChanged();
loadJSONTrailers();
loadJSONReview();
}
private void loadJSONTrailers() {
int movie_id = getIntent().getExtras().getInt("id");
try {
if (BuildConfig.THE_MOVIE_DB_API_TOKEN.isEmpty()) {
Toast.makeText(this, "Please obtain API KEY", Toast.LENGTH_SHORT).show();
return;
}
Client Client = new Client();
Service apiService = Client.getClient().create(Service.class);
Call<TrailerResponse> call = apiService.getMovieTrailer(movie_id, BuildConfig.THE_MOVIE_DB_API_TOKEN);
call.enqueue(new Callback<TrailerResponse>() {
@Override
public void onResponse(Call<TrailerResponse> call, Response<TrailerResponse> response) {
List<Trailer> trailers = response.body().getResuts();
rvDetail.setAdapter(new TrailerAdapter(getApplicationContext(), trailers));
rvDetail.smoothScrollToPosition(0);
}
@Override
public void onFailure(Call<TrailerResponse> call, Throwable t) {
Log.d("Error", t.getMessage());
Toast.makeText(DetailActivity.this, "Error fetching Trailer", Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Log.d("Error", e.getMessage());
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
}
private void loadJSONReview() {
int movie_id = getIntent().getExtras().getInt("id");
try {
if (BuildConfig.THE_MOVIE_DB_API_TOKEN.isEmpty()) {
Toast.makeText(this, "Please obtain API KEY", Toast.LENGTH_SHORT).show();
return;
}
Client Client = new Client();
Service apiService = Client.getClient().create(Service.class);
Call<ReviewResponse> call = apiService.getMovieReviews(movie_id, BuildConfig.THE_MOVIE_DB_API_TOKEN);
call.enqueue(new Callback<ReviewResponse>() {
@Override
public void onResponse(Call<ReviewResponse> call, Response<ReviewResponse> response) {
List<Review> reviews = response.body().getResults();
rvReview.setAdapter(new ReviewAdapter(getApplicationContext(), reviews));
rvReview.smoothScrollToPosition(0);
Log.d(TAG, "Here>>>>>>>>>>>>>>>>");
}
@Override
public void onFailure(Call<ReviewResponse> call, Throwable t) {
Log.d("Error", t.getMessage());
Toast.makeText(DetailActivity.this, "Error fetching Review", Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Log.d("Error", e.getMessage());
Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
}
}
public void addFavorites() {
int movie_id = getIntent().getExtras().getInt("id");
dbHelper = new MovieDbHelper(activity);
favoriteMovie = new Movie();
String rate = getIntent().getExtras().getString("vote_average");
String poster = getIntent().getExtras().getString("poster_path");
favoriteMovie.setId(movie_id);
favoriteMovie.setOriginalTitle(movieName.getText().toString().trim());
favoriteMovie.setPosterPath(poster);
favoriteMovie.setVoteAverage(Double.parseDouble(rate));
favoriteMovie.setOverview(synopsis.getText().toString().trim());
favoriteMovie.setReleaseDate(releaseDate.getText().toString().trim());
dbHelper.addFavorites(favoriteMovie);
Log.d(TAG, "Added fav.....");
}
private void removeFromFavorites(int id) {
getApplicationContext().getContentResolver().delete(MovieContract.MovieEntry.CONTENT_URI, MovieContract.MovieEntry.COLUMN_MOVIE_ID + " = ?",
new String[]{String.valueOf(id)});
}
private boolean checkFavoriteMovie(int id) {
Cursor cursor = activity.getContentResolver().query(MovieContract.MovieEntry.CONTENT_URI, null, MovieContract.MovieEntry.COLUMN_MOVIE_ID + " = " + id, null, null);
assert cursor != null;
if (cursor.getCount() <= 0) {
cursor.close();
return false;
}
cursor.close();
return true;
}
}
ReviewAdapter
public class ReviewAdapter extends
RecyclerView.Adapter<ReviewAdapter.MyViewHolder>{
private Context mContext;
private List<Review> reviewsList;
public ReviewAdapter(Context mContext, List<Review> reviewsList){
this.mContext = mContext;
this.reviewsList = reviewsList;
}
@Override
public ReviewAdapter.MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.review, viewGroup, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(final ReviewAdapter.MyViewHolder holder, int i){
holder.reviewAuthor.setText(reviewsList.get(i).getAuthor());
holder.reviewContent.setText(reviewsList.get(i).getContent());
}
@Override
public int getItemCount(){
return reviewsList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView reviewAuthor;
TextView reviewContent;
public MyViewHolder(View view){
super(view);
reviewAuthor = view.findViewById(R.id.review_author);
reviewContent = view.findViewById(R.id.review_content);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = getAdapterPosition();
if(pos != RecyclerView.NO_POSITION){
String author = reviewsList.get(pos).getAuthor();
String content = reviewsList.get(pos).getContent();
reviewAuthor.setText(author);
reviewContent.setText(content);
}
}
});
}
}
}
任何建议都非常感谢我的问题是recyclerview不显示任何数据,但它确实用JSON中的端点显示它们。我也可以链接我的 github,但你需要获取 another API KEY from here 。
我的github链接是here
非常感谢。
最佳答案
您的 RecyclerView
高度可能被评估为“零”。
为了调试此问题,您可以将固定 android:layout_height
设置为某个更大的固定值。
关于java - RecyclerView 不显示数据 1 正在工作,但其他没有显示任何内容,有什么想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50024395/
我为我的一些问题设置了标签。当搜索 labels="ab"时,我得到了相关的标签,但我似乎找不到询问标签的正确语法!="ab"。如何查询不等于ab的? 最佳答案 != 对我有用,尽管它只显示带有标签的
我最近使用 Visual Studio 2013 Express 配置了 GITHUB 和 Demo GITHub 帐户,即用于练习目的。 Good News is that : I have con
我有一个用于播放和暂停的切换按钮。 这是代码: export default (props) => { let [soundState, setSoundState] = useState({ s
一个 XML 文件被发布到我的 spring mvc 正在响应的 URL。 在 .NET 中,我可以这样做: request.Form[0] request.Form["abc"] 或 request
我们的监控脚本遇到问题。 程序流程为 客户将文件(.csv 格式)ftp/sftp 到“源”目录 Bash 脚本将完成的 .csv 文件重命名为 .aaa 文件 另一个 Bash 脚本将“.aaa”文
如果我开始一个线程: new Thread(() -> { while (running) { try { Thread.sl
我正在制作一个看起来像真正的书的 PDF 阅读器。 我在 ScrollView 中有一个 UIImageView 作为书的背景(想象一本打开的书,有空页)。 UIImageView 的层有 2 个子层
创建 Accordion - 在幻灯片上 - 正在滑动的元素下方的元素似乎向下移动了 px,然后又向上移动,从而产生了颤动效果。 $(document).ready(function() { //Pr
我有一个非常奇怪的问题,但只有在运行 Ubuntu 时才会出现(在 CentOS 上一切正常)。我用 Perl 编写了一个脚本并使用了 Mail::IMAPClient模块。 当我运行以下命令时: p
我知道我可以检查 UITextView 是否正在使用 textViewDidBeginEditing: 进行编辑,但我想检查它是否正在使用 if 语句进行编辑? 最佳答案 使用方法isFirstRes
我正在制作一个简单的点击器类型的游戏。问题是,我的 JPanel 忽略了我设置为每秒更新的 Swing 计时器,而是每毫秒更新一次,即使我删除了计时器也是如此。除了计时器的监听器之外,不会在任何地方调
我有以下代码,应该通过组织列表对每个组织进行 td,对每个组织调用 toString 方法,并将结果打印到控制台和名为 Debug1.tab 的文件。 try { StreamWriter p
我有以下代码用于将文件从 url 下载到 sdcard 。此代码适用于小文件,但当文件大时,我下载的文件大小为 0。任何帮助将不胜感激。 Java 代码 setContentView(R.layout
我有一个必须使用 tomcat 部署的 Angular 项目。 Angular 文件在 dist/project-ui/ 中构建文件夹。我复制了 project-ui文件夹到 webapps tomc
我有一堆切换按钮,下面有标签。如果按钮的标签变得太长,那么下一行的第一个按钮将卡在该标签上。 这是我的代码: https://jsfiddle.net/Android272/c150305z/ 我查了
具有特殊字符的 InnerHTML 正在 trim 数据。 elem.innerHTML = displayedObjects.name; 这里的 displayedObjects.name 包含一个
我已经成功地设置了我的证书和 key ,并使用了在这里找到的 mysql 文档: http://dev.mysql.com/doc/refman/5.1/en/replication-solution
在为游戏制作动画和更新计时器时,我读到任何与 GUI 相关的 Activity 都应该在 EDT 上运行,包括重新绘制屏幕。我正在使用单个 ScheduledExecutorService 来更新和绘
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Large numbers erroneously rounded in Javascript 我正在使用
我已经为 .NET RyuJit 安装了新的 Jit 编译器,并按照安装文档中的说明在 regedit 的 .NetFramework 中设置了 AltJit=* 键。 http://blogs.ms
我是一名优秀的程序员,十分优秀!