| Author |
Hashmap in android
|
sachin sandbhor
Greenhorn
Joined: Oct 11, 2010
Posts: 3
|
|
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
Joined: Nov 28, 2008
Posts: 63
|
|
hope this helps!
|
 |
sachin sandbhor
Greenhorn
Joined: Oct 11, 2010
Posts: 3
|
|
|
i used same example but yet it display only 5 items
|
 |
Renjith Mohan
Ranch Hand
Joined: Nov 28, 2008
Posts: 63
|
|
|
Maybe issues in the layout files. Can I see them?
|
 |
sachin sandbhor
Greenhorn
Joined: Oct 11, 2010
Posts: 3
|
|
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 rientation="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 rientation="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
Joined: Nov 28, 2008
Posts: 63
|
|
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.
|
 |
 |
|
|
subject: Hashmap in android
|
|
|