Card View
Card View
>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintTop_toTopOf="parent"
android:padding="10dp"
android:layout_margin="20dp"
app:cardCornerRadius="30dp"
app:cardElevation="10dp"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/image"
android:layout_width="150dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/text"
/>
<TextView
android:id="@+id/text"
android:layout_width="150dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/image"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
=================================================
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</androidx.constraintlayout.widget.ConstraintLayout>
=================================================
package com.example.myapplication;
{
this.Card_name = Card_name;
this.Card_img = Card_img;
}
=================================================
package com.example.myapplication;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
Context context;
ArrayList<Card> Cards_Data;
@Override
public Object getItem(int position) {//position will Entered here from the
Cards_Data arrayLIst
return Cards_Data.get(position);// its mean the position entered will be
for the Cards_Data and it will be returned
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)// witch
view from the Card_List arraylist are selected
{
convertView =
LayoutInflater.from(context).inflate(R.layout.constoum_layout,parent ,
false);//select the view that will be repeat
ImageView Img = convertView.findViewById(R.id.image); //connect this to xml
TextView Text = convertView.findViewById(R.id.text);
Card currentCard = Cards_Data.get(position);
Img.setImageResource(currentCard.Card_img);
Text.setText(currentCard.Card_name);
return convertView;
}
}
=================================================
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
}
}