I am working with ViewGroup
. I want to make a click effect on the item of the group so that User can detect which item is currently clicked. Can anyone please help me?
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
*
* Toast.makeText(getApplicationContext(), "Entertainment ", Toast.LENGTH_SHORT).show();
* ************************/
// tvName.setTextColor(Color.WHITE);
Toast.makeText(getApplicationContext(), "BackTrack ", Toast.LENGTH_SHORT).show();
vv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<SubCategoryItem> subCategoryItems;
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:
Toast.makeText(getApplicationContext(), "Education Entrance ", Toast.LENGTH_SHORT).show();
ArrayList<EducationServiceProviderItem> eduItem;
eduItem = constructEducationListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithEducationInfo(si.getSubcatHeader(), cat_id, eduItem);
break;
case AppConstants.HEALTH:
Toast.makeText(getApplicationContext(), "Helath Entrance ", Toast.LENGTH_SHORT).show();
//TODO write necessary codes for health
ArrayList<HealthServiceProviderItem> healthItem;
healthItem = constructHealthListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithHealthInfo(si.getSubcatHeader(), cat_id, healthItem);
break;
case AppConstants.ENTERTAINMENT:
tvName.setTextColor(Color.GREEN);
Toast.makeText(getApplicationContext(), "Entertainment ", Toast.LENGTH_SHORT).show();
ArrayList<EntertainmentServiceProviderItem> entItem;
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:
Toast.makeText(getApplicationContext(), "Legal ", Toast.LENGTH_SHORT).show();
ArrayList<LegalAidServiceProviderItem>legalItem;
legalItem = constructlegalaidListItemForHeader(cat_id,si.getSubcatHeader());
callMapFragmentWithLegalAidInfo(si.getSubcatHeader(),cat_id,legalItem);
break;
case AppConstants.FINANCIAL:
ArrayList<FinancialServiceProviderItem>financialItem;
financialItem = constructfinancialListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithFinancialInfo(si.getSubcatHeader(), cat_id, financialItem);
break;
case AppConstants.JOB:
ArrayList<JobServiceProviderItem>jobItem;
jobItem = constructjobListItemForHeader(cat_id, si.getSubcatHeader());
callMapFragmentWithJobInfo(si.getSubcatHeader(), cat_id, jobItem);
break;
default:
break;
}
/*code for all*/
}
});
return vv;
}
flag
I have set an OnclickListener. But I can not detect which TextView is clicked now? I have tried to make Text color changed. Suppose I set Text color orange and commmon color black. When the first item has clicked then the text color is orange. When the another item clicked it has become also make be orange. Then two item is orange color. But previous item should be black after clicking next item and only current item should be orange.