android - I want to make items expandable to edit details about place -
someone me how make list item expandable add details particular places.
historical.java
public class historical extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_historical); arraylist<places> places = new arraylist<places>(); places.add(new places("lotus temple","kalkaji",r.drawable.lotus)); places.add(new places("india gate","rajpath",r.drawable.india)); places.add(new places("humayu tomb"," mathura road",r.drawable.humayu)); places.add(new places("tughlaqabad fort","tughlaqabad ",r.drawable.tughlakabad)); places.add(new places("qutub minar","mehrauli",r.drawable.qutub)); places.add(new places("safdarjung tomb","delhi race club",r.drawable.safdarjung)); placeadapter p = new placeadapter(this,places); listview l = (listview) findviewbyid(r.id.list); l.setadapter(p); } }
places.java
package com.example.android.tourguide; public class places { private string name; private int image; private string location; //private int image2; places(string n,string l,int i1/**,int i2*/){ name =n; location = l; image = i1; //image2 = i2; } public string getn() { return name; } public string getlocation() { return location; } public int getimage() { return image; } }
placeadapter
public class placeadapter extends arrayadapter<places> { public placeadapter(activity context, arraylist<places> places) { super(context, 0, places); } @nonnull @override public view getview(int position, @nullable view convertview, @nonnull viewgroup parent) { // check if existing view being reused, otherwise inflate view view listitemview = convertview; if (listitemview == null) { listitemview = layoutinflater.from(getcontext()).inflate(r.layout.list_items, parent, false); } // {@link androidflavor} object located @ position in list places currentword = getitem(position); // find textview in list_item.xml layout id version_name textview miwoktextview = (textview) listitemview.findviewbyid(r.id.name); // version name current androidflavor object , // set text on name textview miwoktextview.settext(currentword.getn()); // find textview in list_item.xml layout id version_number textview defaulttextview = (textview) listitemview.findviewbyid(r.id.location); // version number current androidflavor object , // set text on number textview defaulttextview.settext(currentword.getlocation()); // find imageview in list_item.xml layout id list_item_icon imageview iconview = (imageview) listitemview.findviewbyid(r.id.image); // image resource id current word object , // set image iconview iconview.setimageresource(currentword.getimage()); return listitemview; } }
list_item.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <imageview android:id="@+id/image" android:layout_margin="16dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp" android:layout_torightof="@+id/image"> <textview android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <textview android:id="@+id/location" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:src="@drawable/ic_keyboard_arrow_right_black_24dp" /> </relativelayout>
activity_history.xml
<?xml version="1.0" encoding="utf-8"?> <listview 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:id="@+id/list" tools:context="com.example.android.tourguide.historical"> </listview>
Comments
Post a Comment