• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashmap in android

 
sachin sandbhor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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);

}
 
Renjith Mohan
Ranch Hand
Posts: 65
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hope this helps!
 
sachin sandbhor
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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"
androidrientation="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"
androidrientation="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
  • 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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!