gpt4 book ai didi

Android:更改 ListView 的背景颜色

转载 作者:行者123 更新时间:2023-11-30 03:51:40 26 4
gpt4 key购买 nike

<分区>

在我的应用程序中,我将联系人导入到 ListView 中,试图更改 ListView 的背景颜色,我可以更改整个 ListView 的颜色,但是,我只想更改具有地址和其余部分的联系人的颜色一样。

  @Override
public View getView(int position, View convertView, ViewGroup parent) {

View view = convertView;

if (view == null) {
LayoutInflater inflater = (LayoutInflater) (getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
view = inflater.inflate(renderer, null);
}

TextView text = (TextView) view.findViewById(R.id.name);
ImageView photo = (ImageView) view.findViewById(R.id.photo);

TextView textContNo = (TextView) view.findViewById(R.id.contactno);
TextView textEmailId = (TextView) view.findViewById(R.id.emailId);

Profile contact = listCont.get(position);
text.setText(contact.getName());
contact.getName();
contact.getId();

text.setTag(contact);
text.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
Profile myContact= (Profile) v.getTag();

Intent intent = new Intent();
intent.putExtra("type", profileType);
intent.putExtra("name", myContact.getName());
intent.putExtra("email", myContact.getEmail());
intent.putExtra("contactid", myContact.getId());
intent.putExtra("address", myContact.getAddress());
intent.putExtra("city", myContact.getCity());
intent.putExtra("state", myContact.getState());
intent.putExtra("countryName", myContact.getCountryName());
intent.putExtra("postalCode", myContact.getPostalCode());
intent.putExtra("website", myContact.getWebSite());
intent.putExtra("mobileNumber", myContact.getMobileNo());
intent.putExtra("phoneNumber", myContact.getLandLineNo());
Log.d(TAG, "On Activity Result Method : 1");
activity.setResult(100, intent);

activity.finish();
Constants.loadEntries.cancel(true);
return false;
}
});



if(contact.getPhoto() !=null && !contact.getPhoto().equals("")){
photo.setImageBitmap(contact.getPhoto());
}else{
photo.setImageResource(R.drawable.profile);
}

photo.setTag(contact);
photo.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
Profile myContact= (Profile)v.getTag();

Intent intent = new Intent();
intent.putExtra("type", profileType);
intent.putExtra("name", myContact.getName());
intent.putExtra("email", myContact.getEmail());
intent.putExtra("contactid", myContact.getId());
intent.putExtra("address", myContact.getAddress());
intent.putExtra("website", myContact.getWebSite());
intent.putExtra("mobileNumber", myContact.getMobileNo());
intent.putExtra("phoneNumber", myContact.getLandLineNo());
Log.d(TAG, "On Activity Result Method : 2");
activity.setResult(100, intent);
activity.finish();
Constants.loadEntries.cancel(true);
return false;
}
});

textContNo.setText(contact.getNumber());
textEmailId.setText(contact.getEmail());


view.setClickable(true);
view.setTag(contact);
view.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Profile myContact= (Profile) v.getTag();

Intent intent = new Intent();
intent.putExtra("type", profileType);
intent.putExtra("name", myContact.getName());
intent.putExtra("email", myContact.getEmail());
intent.putExtra("contactid", myContact.getId());
intent.putExtra("address", myContact.getAddress());
intent.putExtra("website", myContact.getWebSite());
intent.putExtra("mobileNumber", myContact.getMobileNo());
intent.putExtra("phoneNumber", myContact.getLandLineNo());
Log.d(TAG, "On Activity Result Method : 3");
activity.setResult(100, intent);
activity.finish();
Constants.loadEntries.cancel(true);
}
});

LinearLayout layout = (LinearLayout)view.findViewById(R.id.profilelayout);
layout.setTag(contact);
layout.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Profile myContact= (Profile) v.getTag();
Intent intent = new Intent();
intent.putExtra("type", profileType);
intent.putExtra("name", myContact.getName());
intent.putExtra("phoneNumber", myContact.getLandLineNo());
intent.putExtra("email", myContact.getEmail());
intent.putExtra("contactid", myContact.getId());
intent.putExtra("address", myContact.getAddress());
intent.putExtra("website", myContact.getWebSite());
intent.putExtra("mobileNumber", myContact.getMobileNo());
Log.d(TAG, "On Activity Result Method : 4");
activity.setResult(100, intent);
activity.finish();
Constants.loadEntries.cancel(true);
}
});


if (position % 2 == 0)
view.setBackgroundResource(R.drawable.listshape);
else
view.setBackgroundResource(R.drawable.favoritebody);
return view;
}

只有当我有联系人地址时,如何更改颜色?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com