Trying accessing and setting image from a class that is not implementing it xml



Hi everybody i have a listview that contains all the contacts of my phone am trying in my xml file to set a image to all of them and trying to set invisible the ones that i don't need to appear i have this :



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.list);
img = (ImageView)findViewById(R.id.img);

Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);

while (phones.moveToNext()){
String name = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

String phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

ContactBean objContact = new ContactBean();
objContact.setName(name);
objContact.setPhoneNo(phoneNumber); //
list.add(objContact);

}
phones.close();


for (int i = 0; i < SQLiteCrudEmc2.Emc2Contacts.length; i++) {

if(!test(SQLiteCrudEmc2.Emc2Contacts[i].toString()) ){
img = (ImageView)findViewById(R.id.img);
Log.i("eeeeeeee",SQLiteCrudEmc2.Emc2Contacts[i].toString() );
Toast.makeText(ContactListActivity.this, "Numéro retrouvé", Toast.LENGTH_LONG).show();
img.setVisibility(View.INVISIBLE);// My problem here
}
}


ContanctAdapter objAdapter = new ContanctAdapter(
ContactListActivity.this, R.layout.alluser_row,list);
listView.setAdapter(objAdapter);

if (null != list && list.size() != 0) {
Collections.sort(list, new Comparator<ContactBean>() {

@Override
public int compare(ContactBean lhs, ContactBean rhs) {
return lhs.getName().compareTo(rhs.getName());
}
});

AlertDialog alert = new AlertDialog.Builder(
ContactListActivity.this).create();
alert.setTitle("");


} else {
showToast("No Contact Found!!!");
}
}


My contats adapter here :



public class ContanctAdapter extends ArrayAdapter<ContactBean> {

private Activity activity;
private List<ContactBean> items;
private int row;
private ContactBean objBean;
ImageView img;

ViewHolder holder;
public ContanctAdapter(Activity act, int row, List<ContactBean> items) {
super(act, row, items);

this.activity = act;
this.row = row;
this.items = items;
}

@SuppressWarnings("null")
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null){
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(row, null);

holder = new ViewHolder();
view.setTag(holder);

} else {
holder = (ViewHolder) view.getTag();
}

if ((items == null)||((position + 1) > items.size()))
return view;

objBean = items.get(position);

holder.tvname = (TextView) view.findViewById(R.id.tvname);
holder.tvPhoneNo = (TextView) view.findViewById(R.id.tvphone);
holder.img = (ImageView)view.findViewById(R.id.img);
if (holder.tvname != null && null != objBean.getName()
&& objBean.getName().trim().length() > 0) {
holder.tvname.setText(Html.fromHtml(objBean.getName()));
}
if (holder.tvPhoneNo != null && null != objBean.getPhoneNo()
&& objBean.getPhoneNo().trim().length() > 0) {
holder.tvPhoneNo.setText(Html.fromHtml(objBean.getPhoneNo()));
}

return view;
}



public class ViewHolder {
public TextView tvname, tvPhoneNo;
ImageView img;

}
public class IsInMyContactsList extends Activity {
public IsInMyContactsList(){

}

public Boolean test(String num){

Boolean isOk = false;
Cursor phone1 = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);

while (phone1.moveToNext()){

String phoneNumber = phone1
.getString(phone1
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if(num.equals(phoneNumber))

isOk = true;

}
phone1.close();


return isOk;

}

}


}


i have a Java.lang.NullPointerExeption please help.


No comments:

Post a Comment