Android 无法确定单击了哪个项目
从列表中,我想查看单击了哪个项目。如果单击一个项目,那么它可以是不同的颜色,以便我们可以将其分开。这里我已经附加了一个开关箱bolow。你能帮我确定点击的项目吗Android 无法确定单击了哪个项目,android,Android,从列表中,我想查看单击了哪个项目。如果单击一个项目,那么它可以是不同的颜色,以便我们可以将其分开。这里我已经附加了一个开关箱bolow。你能帮我确定点击的项目吗 private View getSubCategoryListItemView(final SubCategoryItem si, double dwPercentage, final int cat_id) { LayoutInflater li = LayoutInflater.from(this); View vv
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;
}
private视图GetSubcategory列表项目视图(最终子类别项目si,双dwPercentage,最终整数类别id){
LayoutInflater li=LayoutInflater.from(this);
视图vv=li.充气(R.layout.sub_目录项,llCatListHolder,false);
ImageView ivIcon=(ImageView)vv.findViewById(R.id.iv_子_子_类_图标);
最终文本视图tvName=(文本视图)vv.findViewById(R.id.tv\u sub\u cat\u name);
ivIcon.setImageResource(AppConstants.ALL_CAT_MARKER_ICONS[CAT_id-1]);
ViewGroup.LayoutParams lpIv=ivIcon.getLayoutParams();
lpIv.width=(int)(PrimaryConWidth*dwPercentage);
ivIcon.setLayoutParams(lpIv);
setText(si.getSubcatHeader());
tvName.SettexSize((浮动)(视图宽度*.10*dwPercentage));
/**
*
*单击顶部列表中的子类别项时将调用此OnClickListener
*/
//tvName.setTextColor(Color.WHITE);
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
ArrayList Subcategory Items=GetSubcategory列表(类别id);
对于(子类别项目si:子类别项目){
//tvName.setTextColor(Color.WHITE);
}
tvName.setTextColor(Color.RED);
/*类别代码*/
/*以下代码对于每个类别都是不同的*/
/*类别id 1表示教育。
*类别id 2表示健康
*类别id 3表示娱乐
*类别id 4表示政府
*类别id 5表示合法
*类别id 6表示金融风险
*类别id 7表示工作*/
//tvName.setTextColor(Color.WHITE);
开关(电流类别ID){
案例1.教育:
ArrayList eduItem=ConstructionEducationListItemForHeader(cat_id,si.getSubcatHeader());
callMapFragmentWithEducationInfo(si.getSubcatHeader(),cat_id,eduItem);
打破
案例AppConstants.HEALTH:
//TODO编写必要的健康代码
ArrayList healthItem=constructHealthListItemForHeader(cat_id,si.getSubcatHeader());
callMapFragmentWithHealthInfo(si.getSubcatHeader(),cat_id,healthItem);
打破
case AppConstants.ENTERTAINMENT:
tvName.setTextColor(Color.GREEN);
ArrayList entItem=ConstructionEntertainmentListItemForHeader(cat_id,si.getSubcatHeader());
callMapFragmentWithEntertainmentInfo(si.getSubcatHeader(),cat_id,entItem);
打破
//TODO为娱乐编写必要的代码
案例1.政府:
//为政府编写必要的代码
打破
案例AppConstants.LEGAL:
ArrayListlegalItem=constructlegalaidListItemForHeader(cat_id,si.getSubcatHeader());
callMapFragmentWithLegalAidInfo(si.getSubcatHeader(),cat_id,legalItem);
打破
案例1.1财务:
ArrayList financialItem=ConstructFinancialStitItemForHeader(cat_id,si.getSubcatHeader());
使用FinancialInfo调用MapFragments(si.getSubcatHeader(),目录id,financialItem);
打破
案例AppConstants.JOB:
ArrayList jobItem=constructjobListItemForHeader(cat_id,si.getSubcatHeader());
callMapFragmentWithJobInfo(si.getSubcatHeader(),cat_id,jobItem);
打破
违约:
打破
}
/*所有代码*/
showSubCatListItem.setEnabled(真);
subcatitemlisheader.setText(si.getSubcatHeader());
ConstructionSubcategorityItemList(cat_id,si.getSubcatHeader());
}
});
返回vv;
}
将侦听器添加到项目中,而不是整个视图,然后“视图v”就是单击的项目
否则,您也可以使用ListView和setOnItemClickListener,这将为您提供列表中已单击的项目,但这将取决于您尝试执行的操作。将侦听器添加到项目中列表视图更可取