J'essaie de faire une liste de films, mais il ne montre qu'un écran blanc avec le nom de l'application. Apparemment, j'ai un programme très similaire à celui-ci et il fonctionne parfaitement bien. Voici ce que j'obtiens lorsque je lance le programme.
W/OpenGLRenderer : Impossible de choisir la configuration avec EGL_SWAP_BEHAVIOR_PRESERVED, réessayer sans...
J'ai trouvé quelqu'un qui dit que cette erreur se produit s'il y a une erreur dans les codes xml, mais je vais quand même mettre mes codes java aussi.
public class MainActivity extends AppCompatActivity {
private ListView mListView;
private Context mContext;
ArrayList<Movie> movieList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
final ArrayList<Movie> movieList = Movie.getMoviesFromFile("movies.json", this);
MovieAdapter adapter = new MovieAdapter(this, movieList);
mListView = findViewById(R.id.movie_list_view);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Movie selectedMovie = movieList.get(i);
Intent detailIntent = new Intent(mContext, MovieDetailActivity.class);
detailIntent.putExtra("title", selectedMovie.title);
detailIntent.putExtra("description", selectedMovie.description);
detailIntent.putExtra("poster", selectedMovie.poster);
startActivity(detailIntent);
}
});
}
Voici mon adaptateur.
public class MovieAdapter extends BaseAdapter{
private Context mContext;
private ArrayList<Movie> mMovieList;
private LayoutInflater mInflater;
public MovieAdapter(Context mContext, ArrayList<Movie> mMovieList){
this.mContext = mContext;
this.mMovieList = mMovieList;
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount(){return mMovieList.size();}
@Override
public Object getItem(int pos){return mMovieList.get(pos);}
@Override
public long getItemId(int pos){return pos;}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
ViewHolder holder;
if(convertView == null){
convertView = mInflater.inflate(R.layout.list_item_movie, parent, false);
holder = new ViewHolder();
holder.titleTextView = convertView.findViewById(R.id.title);
holder.charactersTextView = convertView.findViewById(R.id.main_characters);
holder.descriptionTextView = convertView.findViewById(R.id.description);
holder.thumbnailImageView = convertView.findViewById(R.id.poster);
convertView.setTag(holder);
} else{
holder = (ViewHolder)convertView.getTag();
}
TextView titleTextView = holder.titleTextView;
TextView descriptionTextView = holder.descriptionTextView;
TextView charactersTextView = holder.charactersTextView;
ImageView thumbnailImageView = holder.thumbnailImageView;
Movie movie = (Movie)getItem(pos);
titleTextView.setText(movie.title);
titleTextView.setTextSize(20);
charactersTextView.setText(movie.main_characters);
charactersTextView.setTextSize(13);
descriptionTextView.setText(movie.description);
descriptionTextView.setTextSize(9);
Picasso.with(mContext).load(movie.poster).into(thumbnailImageView);
return convertView;
}
private static class ViewHolder{
public TextView titleTextView;
public TextView descriptionTextView;
public ImageView thumbnailImageView;
public TextView charactersTextView;
}
}
Et les suivants sont les codes xml.
activité_main.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"
tools:context="com.example.user.junepyolee_miniapp1.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/movie_list_view" />
liste_item_movie.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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/poster"
android:layout_width="90dp"
android:layout_height="140dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="4dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_centerVertical="true"
android:scaleType="fitCenter"
android:contentDescription="This is a thumbnail"
app:srcCompat="@mipmap/ic_launcher" />
<RelativeLayout
android:id="@+id/movie_list_text_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/poster"
android:layout_alignParentTop="false"
android:layout_toRightOf="@+id/poster">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="Title"
android:textSize="20sp" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:maxLines="3"
android:text="description"
android:textSize="9sp" />
<TextView
android:id="@+id/main_characters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/description"
android:layout_below="@+id/description"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="characters max 3 people"
android:textSize="13sp" />
<TextView
android:id="@+id/hasSeen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/main_characters"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:text="has seen?"
android:textSize="11sp" />
</RelativeLayout>
Quelqu'un a-t-il une solution pour ce problème ?