Android listview hide button - android

I have a problem how to hide the button in specific row in my listview with SimpleAdapter. This is my sample code.
alert_noti_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
alert_pop_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="view1"
android:textSize="20dp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/confirm"
android:layout_toStartOf="#+id/confirm" />
<TextView
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="10dp"
android:textStyle="bold"
android:visibility="visible"
android:layout_below="#+id/view1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/confirm"
android:layout_toStartOf="#+id/confirm" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/confirm"
android:layout_alignBottom="#+id/view2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/ic_confirm" />
</RelativeLayout>
Activity :
List<Map<String, String>> listData = new ArrayList<Map<String, String>>();
Map<String, Object> names = new HashMap<String, Object>();
names.put("First","head1");
names.put("Second", "txt1");
names.put("First","head2");
names.put("Second", "txt2");
names.put("First","head3");
names.put("Second", "txt3");
...
listData.add((HashMap) names);
ListView lv = (ListView) dialog_mail.findViewById(R.id.listView1);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(home.this,, android.R.layout.two_line_list_item, names);
SimpleAdapter adapter = new SimpleAdapter(home.this, listData,
R.layout.alert_pop_list,
new String[] {"First", "Second" },
new int[] {R.id.view1, R.id.view2});
lv.setAdapter(adapter);
how do i hide the button if the value is head2 and show to the rest of the list.

You need to custom a BaseAdapter instead of SimpleAdapter and write some code at getView() method。 just like:
public View getView(int p,View view,ViewGroup parent) {
if (view == null) {
view = LayoutInflate.xxxx;
}
Button btn = (Button) view.findViewById(R.id.btn);
DataModel d = list.get(p);
if (d.isHidden || d.data.equals("head2")) {
btn.setVisibility(View.GONE);
} else {
btn.setVisibility(View.visible);
}
return view;
}
so you need to create a DataModel to store some property.
public class DataModel {
public boolean isHidden;
public HashMap<String,String> dataMap;
//and so on.....
}

Related

how to display Not Listview found item in android

public static void loadPopupData(Context context, final ListView listView) {
final DataBaseManager dbManager1 = new DataBaseManager(context);
final ArrayList<Notify> notifies = dbManager1.getNotificationList(15);
Notifcationadapter adapter = new Notifcationadapter(context, notifies);
listView.setAdapter(adapter);
listView.setEmptyView(emptyView);
}
This method is use to Print data In listview :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup"
android:layout_width="fill_parent"
android:layout_height="350dip" >
<RelativeLayout
android:id="#+id/rl_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:background="#00000000" >
<ImageView
android:id="#+id/image_tringle"
android:layout_width="40px"
android:layout_height="21px"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="50dp"
android:src="#drawable/notficationarrow_icon" />
</RelativeLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/textView1"
android:background="#anim/notifcationitembroder" >
</ListView>
<TextView android:id="#+id/emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/listView1"
android:layout_alignBottom="#+id/listView1"
android:gravity="center"
android:visibility="invisible"
android:text="No items in list" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rl_top"
android:background="#drawable/bgnotifcationlayoutback"
android:gravity="center"
android:paddingBottom="20dp"
android:text="Notification"
android:textColor="#666666"
android:paddingTop="2dp"
android:textSize="20dip"
android:textStyle="bold" />
</RelativeLayout>
This is Xml File where am Printing Listview .
i want when there is no item in Listview then it should display Not found Listview am try to do But unable to display it please suggest me how to display Not found item if there is not item in list view .
You can use empty views for listview
Setting emptyview to Listview
Try this one. If this is not your solution in else add another view to display there is no any records to display
public String[] getSociety() {
int pos = 0;
MFDbBHelper mDbHelper = new MFDbBHelper(this);
List<Society> society = mDbHelper.getAllSociety();
String[] values = null;
if (society.size() > 0) {
values = new String[society.size()];
for (Society socty : society) {
values[pos] = socty.get_society_name();
// Writing Society to log
String log = "Id: " + socty.get_society_id() + " ,Name: "
+ socty.get_society_name();
Log.d("Insert: ", log);
pos++;
}
} else {
values = new String[0];
values[0] = "No records found!";
}
return values;
}
Add a text view which shows "No Results" in your popup's xml file and give it a id.
something like this
<TextView android:id="#+id/emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#+id/listView1"
android:layout_alignBottom="#+id/listView1"
android:gravity="center"
android:text="No items in list"
android:visibility="invisible"/>
And in code part set the textview as emptyview of your listview.
public static void loadPopupData(Context context, final ListView listView) {
final DataBaseManager dbManager1 = new DataBaseManager(context);
final ArrayList<Notify> notifies = dbManager1.getNotificationList(15);
Notifcationadapter adapter = new Notifcationadapter(context, notifies);
listView.setAdapter(adapter);
listView.setEmptyView(findViewById(R.id.emptyView));
}
Please add this in your xml
<TextView android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Results" />
and this code in your activity contains list
public static void loadPopupData(Context context, final ListView listView) {
final DataBaseManager dbManager1 = new DataBaseManager(context);
final ArrayList<Notify> notifies = dbManager1.getNotificationList(15);
Notifcationadapter adapter = new Notifcationadapter(context, notifies);
listView.setAdapter(adapter);
listView.setEmptyView(findViewById(android.R.id.empty));
}

How to get two textviews in a listview on the same line?

I have two TextViews tvA and tvB which appear in a ListView lvA.
tvA and tvB display data pulled from a Sqlite Database using Cursor.
Cursor cursor = myDb.getAllRows();
String[] from = new String[]
{DBAdapter.KEY_A,DBAdapter.KEY_B};
int[] to = new int[]
{R.id.tvA,R.id.tvB};
SimpleCursorAdapter myCursorAdapter =new SimpleCursorAdapter(this,R.layout.lvA, cursor,from,to);
myList = (ListView) findViewById(R.id.lvA);
myList.setAdapter(myCursorAdapter);
registerForContextMenu(myList);
The issue is that tvA and tvB doesn't appear as one item in lvA (i.e. they don't appear on the same line) and appear as two different items.
Below is the XML:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="5dip"
>
<TextView
android:id="#+id/tvA"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"/>
<TextView
android:id="#+id/tvB"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_toRightOf="#id/tvA"/>
</RelativeLayout>
If you want both the TextViews in the same align then you can use LinearLayout with android:layout_weight attribute.
To have equal width TextView, give same weight value.
You can use TableLayout
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView android:id="#+id/tvA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</TextView>
<TextView android:id="#+id/tvB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</TextView>
</TableRow></TableLayout >
or LinearLayout with android:orientation="horizontal"
and TextView with android:layout_weight="1"
Here's how I do it with three items on the same row = This is my item list filled from a cursor
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TextView_StudentName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:maxWidth="75dp"
android:layout_gravity="left"
android:text="#string/student_id"
android:padding="5dp"></TextView>
<TextView
android:id="#+id/TextView_StudentLocation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:maxWidth="75dp"
android:gravity="center"
android:text="#string/student_Location"
android:padding="5dp"></TextView>
<TextView
android:id="#+id/TextView_StudentClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:maxWidth="75dp"
android:layout_alignParentRight="true"
android:text="#string/student_class" >
</TextView>
</RelativeLayout>`
I'm in the process of replacing the hard sizes with info from the dimen file, but so far this has worked.
TRY this :
Main Java:
//DECLARE:
private Map<String, Map<String, String>> mMenuView = new HashMap<String, Map<String, String>>();
//IN onCreateView
Adapter mAdapter = new NewAdapter(getActivity().getApplicationContext(), mMenuView);
mListView.setAdapter(mAdapter);
// ADD onActivityCreated or onStart save data from your DB and store in mMenuView
Map<String, String> tempMap = new HashMap<String, String>();
tempMap.put("TEXTVALE_A", datafromdb_A);
tempMap.put("TEXTVALE_B", datafromdb_B);
mMenuView.put(Integer.toString(mMenuView.size()), tempMap);
}
//NEWADAPTER
private class NewAdapter extends BaseAdapter {
private Context mContext;
private TextView mTitle1;
private TextView mTitle2;
private Map<String, Map<String, String>> mData = new HashMap<String, Map<String, String>>();
public NewAdapter(Context applicationContext,Map<String, Map<String, String>> mMenuValue) {
mContext = applicationContext;
mData = mMenuValue;
}
#Override
public int getCount() {
return mData.size();
}
#Override
public Map<String, String> getItem(int position) {
return mData.get(Integer.toString(position));
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Map<String, String> data = mData.get(Integer.toString(position));
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.linear_layout, null);
mTitle1 = (TextView) convertView.findViewById(R.id.t1A);
mTitle2 = (TextView) convertView.findViewById(R.id.t1B);
}
if (data != null) {
mTitle1.setText(data.get("TEXTVALE_A"));
mTitle2.setText(data.get("TEXTVALE_B"));
}
return convertView;
}
}
linear_layout.xml
<LinearLayout
android:id="#+id/content_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:id="#+id/tab1_wrapper"
android:layout_width="0dip"
android:layout_height="50dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center|center_horizontal"
>
<TextView
android:id="#+id/t1A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="13sp"
android:gravity="center|center_horizontal"
android:textColor="#color/text_color3x"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2_wrapper"
android:layout_width="0dip"
android:layout_height="50dp"
android:layout_weight="0.5"
android:orientation="vertical"
android:gravity="left|center_vertical|center_horizontal"
>
<TextView
android:id="#+id/A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="13sp"
android:gravity="center|center_horizontal"
/>
</LinearLayout>
</LinearLayout>

Not getting List View on DIalog box

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>
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);

How to add static header image in custom listview?

I will put a picture on top of a custom list view for the header image, but the image is repeated, how can I make it can't click and non-repeatable?
this is my xml code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/abs__background_holo_light" >
<ImageView
android:id="#+id/detailImage"
android:layout_width="wrap_content"
android:layout_height="140dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"
android:src="#drawable/pantaigoacina" />
<RelativeLayout
android:id="#+id/detailLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/detailImage"
android:background="#color/abs__background_holo_light" >
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="5dip"
android:layout_marginTop="20dip"
android:background="#color/abs__background_holo_light"
android:padding="5dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="15dip"
android:layout_height="15dip"
android:src="#drawable/arrow"
android:contentDescription="#string/app_name"/>
</LinearLayout>
<TextView
android:id="#+id/NamaLokasi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail"
android:text="Pantai Sipelot"
android:textColor="#040404"
android:textSize="18sp"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="#+id/detailLokasi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/NamaLokasi"
android:layout_marginRight="20dip"
android:layout_marginTop="5dip"
android:layout_toRightOf="#+id/thumbnail"
android:text="Deskripsi Konten, Lokasi Berada di Desa Wilayah Malang"
android:textColor="#343434"
android:textSize="12sp" />
</RelativeLayout>
</RelativeLayout>
this is my adapter :
String[] from = { "pantai", "detail" };
int[] to = { R.id.NamaLokasi, R.id.detailLokasi };
SimpleAdapter adapter = new SimpleAdapter(getActivity()
.getBaseContext(), aList, R.layout.fragment_detail, from,
to);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
Remove the image form the xml.
ImageView iv = new ImageView(getActivity());
// set image to imageview
ListView list = getListView();
list.addHeaderView(headerView);
The docs
public void addHeaderView (View v)
Added in API level 1
Add a fixed view to appear at the top of the list. If addHeaderView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.
Note: When first introduced, this method could only be called before setting the adapter with setAdapter(ListAdapter). Starting with KITKAT, this method may be called at any time. If the ListView's adapter does not extend HeaderViewListAdapter, it will be wrapped with a supporting instance of WrapperListAdapter.
Parameters
v The view to add.
Edit:
#Override
public void onActivityCreated(Bundle savedInstanceStat)
{
super.onActivityCreated(savedInstanceState);
list = getListView();
ImageView imageHeaderView = new ImageView(getActivity());
imageHeaderView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.pantaigoacina));
list.addHeaderView(imageHeaderView);
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < DaerahWisata.pantai.length; i++) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("pantai", DaerahWisata.pantai[i]);
hm.put("detail", "Lokasi : \r\n" + DaerahWisata.detailp[i]);
aList.add(hm);
}
String[] from = { "pantai", "detail" };
int[] to = { R.id.NamaLokasi, R.id.detailLokasi };
SimpleAdapter adapter = new SimpleAdapter(getActivity()
.getBaseContext(), aList, R.layout.fragment_detail, from,
to);
setListAdapter(adapter);
}
Edit, if want to set imageview from other xml layout :
list = getListView();
Context context = getListView().getContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.image_header, null);
list.addHeaderView(view);
Try below code:-
ImageView imageHeaderView = new ImageView(this);//use getActivity() on fragment
imageHeaderView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.deckblatt));
myList.addHeaderView(imageHeaderView);

ArrayList of Hashmaps to ListView nullpointerexception

I keep getting this error:
Unable to start activity ComponentInfo{com.Nostradamus/com.Nostradamus.Contactenlijst}: java.lang.NullPointerException
And I don't know what I do wrong.
It has something to do with the last code:
lv.setAdapter(new SimpleAdapter(this, mylist, R.layout.list_item, from, to));
This is my java code:
public class Contactenlijst extends Activity {
ListView lv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] from = new String[] {"voornaam", "achternaam", "geboortedatum", "adres", "postcode", "woonplaats", "email", "telefoon"};
int[] to = new int[]{R.id.voornaam, R.id.achternaam, R.id.geboortedatum, R.id.adres, R.id.postcode, R.id.woonplaats, R.id.email, R.id.telefoon};
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
Log.d("test","test2");
// Get the data (see above)
JSONObject json = Database
.getJSONfromURL("http://fabian.nostradamus.nu/Android/getcontactinfo.php");
Log.d("test","test3");
try {
JSONArray contactinfo = json.getJSONArray("contactlijst");
Log.d("test","test4");
// Loop the Array
for (int i = 0; i < contactinfo.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = contactinfo.getJSONObject(i);
map.put("voornaam", e.getString("staff_name"));
map.put("achternaam", e.getString("staff_lastname"));
map.put("geboortedatum", e.getString("staff_dateofbirth"));
map.put("adres", e.getString("staff_address"));
map.put("postcode", e.getString("staff_address_postal"));
map.put("woonplaats", e.getString("staff_address_city"));
map.put("email", e.getString("staff_email"));
map.put("telefoon", e.getString("staff_phone"));
mylist.add(map);
Log.e("test",map.toString());
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
lv = (ListView) findViewById(R.id.list);
lv.setAdapter(new SimpleAdapter(this, mylist, R.layout.list_item, from, to));
}
}
And these are my xmls:
Contactenlijst
<?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">
<TextView android:id="#+id/voornaam"
android:layout_width="50dip"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/achternaam"
android:layout_width="70dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="#+id/geboortedatum"
android:layout_width="60dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="#+id/adres"
android:layout_width="50dip"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/postcode"
android:layout_width="70dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="#+id/woonplaats"
android:layout_width="60dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="#+id/email"
android:layout_width="60dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="#+id/telefoon"
android:layout_width="60dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
Contactview
<?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/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:drawSelectorOnTop="false"/>
<TextView android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data">
</TextView>
</LinearLayout>
and Listitem
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
you didn't set the layout using
setContentView(R.layout.yourlayout);
so without add layout you are using your listview that's why you getting NullPointerException.
add this above line after
super.onCreate(savedInstanceState);
or before the use listview object
You need to call setContentView(...) before lv = (ListView) findViewById(R.id.list);
setContentView(...) inflates the XML file for your layout. If you don't do this, then lv will be null.

Categories

Resources