所以实际上我在一个屏幕上有一个 MapActivity 和 ListActivity ,当用户单击地图上的一个 Pin 时,单击的位置将位于列表的顶部,并且具有不同的背景和分隔线颜色。
所以我开始发送点击的Pin的纬度并在getView()上检索它,如果点击的纬度与第一个条目上显示的纬度相同,它会做一些事情。
我已经设法使 ListView 的第一个条目具有一定的背景,但是当我向下滚动列表时,其他一些条目的背景也发生了变化。
这是我的方法:
double selectedLat = WWHApplication.getSelectedLatitude();
DecimalFormat df = new DecimalFormat("#.#####");
String dLat = df.format(lat);
String sLat = df.format(selectedLat);
if (position == 0) {
if (dLat.equals(sLat)) {
feedViewHolder.layout
.setBackgroundResource(R.drawable.list_segment_selected);
}
}
如何仅在第一项上更改分隔线的颜色和 ListView 的背景?如果有人可以在这种情况下帮助我,我真的很感激,我也愿意接受任何其他解决方案。谢谢你。
更新:这是getView()
方法
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FeedViewHolder feedViewHolder = null;
final VideoLocationDB vidLocation = videoLocationsDB[position];
String url = vidLocation.documentary_thumbnail_url;
String name = vidLocation.name;
String title = vidLocation.name;
String desc = vidLocation.text;
double lat = vidLocation.latitude;
double lng = vidLocation.longitude;
String distance = calculateDistance(lat, lng);
// System.out.println("ON LOC DISTANCE: "+distance);
if (convertView == null) {
// convertView = LocationsListActivity.this.getLayoutInflater()
// .inflate(R.layout.listitems, null, true);
convertView = layoutInflater.inflate(R.layout.listitems,
parent, false);
feedViewHolder = new FeedViewHolder();
feedViewHolder.layout = (LinearLayout) convertView
.findViewById(R.id.list_bg);
feedViewHolder.titleView = (TextView) convertView
.findViewById(R.id.txt_title);
feedViewHolder.descView = (TextView) convertView
.findViewById(R.id.txt_list_desc);
feedViewHolder.more = (TextView) convertView
.findViewById(R.id.txt_more);
feedViewHolder.distanceView = (TextView) convertView
.findViewById(R.id.txt_distance);
feedViewHolder.v = (ImageView) convertView
.findViewById(R.id.image);
Typeface fontRegular = Typeface.createFromAsset(getAssets(),
"miso.otf");
feedViewHolder.titleView.setTypeface(fontRegular);
Typeface fontLight = Typeface.createFromAsset(getAssets(),
"miso-light.otf");
feedViewHolder.descView.setTypeface(fontLight);
feedViewHolder.more.setTypeface(fontLight);
feedViewHolder.distanceView.setTypeface(fontRegular);
convertView.setTag(feedViewHolder);
} else {
feedViewHolder = (FeedViewHolder) convertView.getTag();
}
feedViewHolder.v.setTag(url);
loader.DisplayImage(url, LocationsListActivity.this,
feedViewHolder.v, name);
double selectedLat = WWHApplication.getSelectedLatitude();
DecimalFormat df = new DecimalFormat("#.#####");
String dLat = df.format(lat);
String sLat = df.format(selectedLat);
if (position == 0) {
if (dLat.equals(sLat)) {
feedViewHolder.layout
.setBackgroundResource(R.drawable.list_segment_selected);
}
}
feedViewHolder.titleView.setText(title.toUpperCase());
feedViewHolder.descView.setText(desc);
feedViewHolder.more.setText(getString(R.string.de_list_more));
feedViewHolder.distanceView.setText(distance);
return convertView;
}