从列表中,我想查看单击了哪个项目。如果单击某个项目,则它可以采用不同的颜色,以便我们将其分开。在这里,我附上了一个开关箱防尘罩。您能帮我确定点击项目吗?
private View getSubCategoryListItemView(final SubCategoryItem si, double dwPercentage, final int cat_id) {
LayoutInflater li = LayoutInflater.from(this);
View vv = li.inflate(R.layout.sub_cat_list_item, llCatListHolder, false);
ImageView ivIcon = (ImageView) vv.findViewById(R.id.iv_sub_cat_icon);
final TextView tvName = (TextView) vv.findViewById(R.id.tv_sub_cat_name);
ivIcon.setImageResource(AppConstants.ALL_CAT_MARKER_ICONS[cat_id-1]);
ViewGroup.LayoutParams lpIv = ivIcon.getLayoutParams();
lpIv.width = (int) (primaryIconWidth * dwPercentage);
ivIcon.setLayoutParams(lpIv);
tvName.setText(si.getSubcatHeader());
tvName.setTextSize((float) (VIEW_WIDTH * .10 * dwPercentage));
/**
*
*This OnClickListener will be called for clicking subcategory items from the top list
*/
// tvName.setTextColor(Color.WHITE);
vv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<SubCategoryItem> subCategoryItems = getSubCategoryList(cat_id);
for(SubCategoryItem si : subCategoryItems) {
// tvName.setTextColor(Color.WHITE);
}
tvName.setTextColor(Color.RED);
/*code for category*/
/*following code will be different for each category*/
/*category id 1 means education.
* category id 2 means health
* category id 3 means entertainment
* category id 4 means government
* category id 5 means legal
* category id 6 means financial
* category id 7 means job*/
// tvName.setTextColor(Color.WHITE);
switch (currentCategoryID) {
case AppConstants.EDUCATION:
ArrayList<EducationServiceProviderItem> eduItem = constructEducationListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithEducationInfo(si.getSubcatHeader(), cat_id, eduItem);
break;
case AppConstants.HEALTH:
//TODO write necessary codes for health
ArrayList<HealthServiceProviderItem> healthItem = constructHealthListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithHealthInfo(si.getSubcatHeader(), cat_id, healthItem);
break;
case AppConstants.ENTERTAINMENT:
tvName.setTextColor(Color.GREEN);
ArrayList<EntertainmentServiceProviderItem> entItem = constructEntertainmentListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithEntertainmentInfo(si.getSubcatHeader(), cat_id, entItem);
break;
//TODO write necessary codes for entertainment
case AppConstants.GOVERNMENT:
//TODO write necessary codes for government
break;
case AppConstants.LEGAL:
ArrayList<LegalAidServiceProviderItem>legalItem = constructlegalaidListItemForHeader(cat_id,si.getSubcatHeader());
callMapFragmentWithLegalAidInfo(si.getSubcatHeader(),cat_id,legalItem);
break;
case AppConstants.FINANCIAL:
ArrayList<FinancialServiceProviderItem> financialItem = constructfinancialListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithFinancialInfo(si.getSubcatHeader(), cat_id, financialItem);
break;
case AppConstants.JOB:
ArrayList<JobServiceProviderItem> jobItem = constructjobListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithJobInfo(si.getSubcatHeader(), cat_id, jobItem);
break;
default:
break;
}
/*code for all*/
showSubCatListItem.setEnabled(true);
subCatItemListHeader.setText(si.getSubcatHeader());
constructSubCategoryItemList(cat_id, si.getSubcatHeader());
}
});
return vv;
}
最佳答案
将侦听器添加到项目。最好使用Listview。