• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hashmap in android

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used custom xml file for listview.
i create two textview in listview but only five items are displaying on screen.
What is the problem? why not all items are displaying?



public class MyCustomListView extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_list_view);

SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.custom_row_view,
new String[] {"name","height"},
new int[] {R.id.text1,R.id.text2}
);
populateList();
setListAdapter(adapter);
}

static final ArrayList<HashMap<String,String>> list =
new ArrayList<HashMap<String,String>>();

private void populateList() {
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("name","Chavand");
temp.put("height", "3400ft");
list.add(temp);
HashMap<String,String> temp1 = new HashMap<String,String>();
temp1.put("name","Durg-Dhakoba");
temp1.put("height", "3900ft & 4100ft");
list.add(temp1);
HashMap<String,String> temp2 = new HashMap<String,String>();
temp2.put("name","Hadsar");
temp2.put("height", "3200ft");
list.add(temp2);
HashMap<String,String> temp3 = new HashMap<String,String>();
temp3.put("name","Jivdhan");
temp3.put("height", "3754ft");
list.add(temp3);
HashMap<String,String> temp4 = new HashMap<String,String>();
temp4.put("name","Korigad");
temp4.put("height", "3000ft");
list.add(temp4);
HashMap<String,String> temp5 = new HashMap<String,String>();
temp.put("name","Lohgad");
temp.put("height", "3400ft");
list.add(temp5);
HashMap<String,String> temp6 = new HashMap<String,String>();
temp.put("name","Malhargad");
temp.put("height", "3100ft");
list.add(temp6);
HashMap<String,String> temp7 = new HashMap<String,String>();
temp.put("name","Shivneri");
temp.put("height", "3500ft");
list.add(temp7);
HashMap<String,String> temp8 = new HashMap<String,String>();
temp.put("name","Visapur");
temp.put("height", "3038ft");
list.add(temp8);

}
 
Ranch Hand
Posts: 65
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hope this helps!
 
sachin sandbhor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i used same example but yet it display only 5 items
 
Renjith Mohan
Ranch Hand
Posts: 65
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe issues in the layout files. Can I see them?
 
sachin sandbhor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
custom.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<TextView android:id="@+id/text1"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#FFFF00"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/text2"
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>

</LinearLayout>



main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000fff"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFff00"
android:text="No data"
/>
</LinearLayout>
 
Renjith Mohan
Ranch Hand
Posts: 65
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

HashMap<String,String> temp5 = new HashMap<String,String>();
temp.put("name","Lohgad");
temp.put("height", "3400ft");
list.add(temp5);



Looks like you forgot to change the variable name! See variables highlighted in blue.
reply
    Bookmark Topic Watch Topic
  • New Topic