Reputation: 29
Problem is with its showing me nullpointer exception while click onshowContact button there is something wrong i cant figure it out but I m not getting the dialog box with the list view with this code Button click of contact view
public void showContacts(View view){
//View CSV into an array
try{
Dialog dialog = new Dialog(NewMessage.this);
dialog.setContentView(R.layout.contact_view);
dialog.setTitle("Contacts");
dialog.setCancelable(true);
ListView lv = (ListView)findViewById(R.id.lv);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
int fillarray = 0;
if(mylist.equals(null)){
fillarray = 0;
}
else{
fillarray = mylist.size();
}*/
for(int i=0;i<name.size();i++)
{
HashMap<String, String> map = new HashMap<String, String>();
map.put("name",name.get(i));
map.put("number",number.get(i));
map.put("status",status.get(i));
mylist.add(map);
}
SimpleAdapter mSchedule = new SimpleAdapter(NewMessage.this, mylist, R.layout.view_csv, new String[] {"name","number","status"}, new int[] {R.id.t1,R.id.t2,R.id.t3});
lv.setAdapter(mSchedule);
dialog.show();
}
catch(Exception e){
Toast.makeText(NewMessage.this, e.toString(), 2000).show();
}
//Viewing Finish Here
}
This my contact_view.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" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="397dp" >
</ListView>
</LinearLayout>
This my view_csv.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/t1"
android:layout_width="90dip"
android:layout_height="wrap_content"
android:text="text1"/>
<TextView
android:id="@+id/t2"
android:layout_width="90dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text2"/>
<TextView
android:id="@+id/t3"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text3" />
</LinearLayout>
Upvotes: 0
Views: 404
Reputation: 5150
Your ListView is comming under contact_view
layout. So you have to initialize the list through your dialog. because your dialog contains the layout here dialog.setContentView(R.layout.contact_view);
So you have to initialize the list like:
ListView lv = (ListView) dialog.findViewById(R.id.lv);
Upvotes: 1