Hey guys I have initialized the list view in my android quotation application. Now I want when the user tape on for example the life quotes then all the quotes of life should show on cardView separately. I don't know how to show each quote on each cardView please direct me to the right path I'll be very thankful.
this is the quotes activity from where i go to all other activities
public class QoutesActivity extends AppCompatActivity {
private ListView listView;
// Listview Adapter
ArrayAdapter<String> adapter;
String[] listItems = {
"Happiness Quotes",
"Attitude Quotes",
"Anniversary Quotes",
"Life Quotes",
"Alone Quotes",
"Strength Quotes",
"Patriotism Quotes" ,
"Hope Quotes" ,
"Inspirational Quotes" ,
"Independence Quotes" ,
"Childhood Quotes" ,
"Trust Quotes",
"Selfie Quotes",
"Birthday Quotes" ,
"Knowledge Quotes" ,
"Love Quotes" ,
"Nature Quotes"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qoutes);
listView = findViewById(R.id.list_view);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(QoutesActivity.this,
android.R.layout.simple_list_item_1,listItems) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the current item from ListView
View view = super.getView(position, convertView, parent);
// Get the Layout Parameters for ListView Current Item View
ViewGroup.LayoutParams params = view.getLayoutParams();
// Set the height of the Item View
params.height = 180;
view.setLayoutParams(params);
return view;
}
};
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String itemValue = (String) listView.getItemAtPosition(position);
if (position == 0) {
//code specific to first list item
Intent myIntent = new Intent(view.getContext(), HappinessActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 1){
Intent myIntent = new Intent(view.getContext(), AttitudeActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 2){
Intent myIntent = new Intent(view.getContext(), AnniversaryActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 3){
Intent myIntent = new Intent(view.getContext(), LifeActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 4){
Intent myIntent = new Intent(view.getContext(), AloneActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 5){
Intent myIntent = new Intent(view.getContext(), StrengthActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 6){
Intent myIntent = new Intent(view.getContext(), PatriotismActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 7){
Intent myIntent = new Intent(view.getContext(), HopeActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 8){
Intent myIntent = new Intent(view.getContext(), InspitationalActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 9){
Intent myIntent = new Intent(view.getContext(), IndependenceActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 10){
Intent myIntent = new Intent(view.getContext(), ChildhoodActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 11){
Intent myIntent = new Intent(view.getContext(), TrustActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 12){
Intent myIntent = new Intent(view.getContext(), SelfieActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 13){
Intent myIntent = new Intent(view.getContext(), BirthdayActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 14){
Intent myIntent = new Intent(view.getContext(), KnowledgeActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 15){
Intent myIntent = new Intent(view.getContext(), LoveActivity.class);
startActivityForResult(myIntent, 0);
}else if (position == 16){
Intent myIntent = new Intent(view.getContext(), NatureActivity.class);
startActivityForResult(myIntent, 0);
}
}
});
}
}
and this this the xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layercontainer"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg3">
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>