我有例如。两个父项,其中第一个有一个孩子,第二个有 3 个孩子。如何显示它。如果我有第二个父视图,那么我没有找到这个视图点击日志。我想知道这个视图是点击日志。
我有多次相同的名字,所以显示一次相同的名字,孩子使用相同的名字。
像这样
Asia -> Japan
Europe-> Spain
Europe->England
现在我想显示
Asia->Japan
Europe-> spain
->England
我对android中的可扩展视图没有更多的想法。
这是 oncreate 的代码:
if (EduInterface.categoryIDArrayList.size() > 0) {
categoryName = new String[EduInterface.categoryNameArrayList
.size()][];
award = new String[EduInterface.pointIDArrayList.size()][];
pointName = new String[EduInterface.pointNameArrayList
.size()][];
pointValue = new String[EduInterface.pointValueArrayList
.size()][];
System.out.println("size of category name is ::"
+ categoryName.length);
int catList = EduInterface.categoryIDArrayList.size();
Log.d("TAG", "Size of Cat===" + catList);
for (int j = 0; j < catList; j++)
{
for (int i = j; i < EduInterface.pointCategoryArrayList
.size(); i++) {
categoryName[j] = new String[1];
categoryName[j][i] = EduInterface.categoryNameArrayList
.get(j);
pointName[j] = new String[1];
pointName[j][i] = EduInterface.pointNameArrayList
.get(j);
pointValue[j] = new String[1];
pointValue[j][i] = EduInterface.pointValueArrayList
.get(j);
System.out.println(j + ")categoryName is ::"
+ categoryName[j][i]
+ " point value is ::" + pointName[j][i]
+ "---" + pointValue[j][i]);
}
}
pointcategoryExpandableList
.setAdapter(new MyExpandableAdapter());
}
在 ExapanableAdater 中:
public class MyExpandableAdapter extends BaseExpandableListAdapter {
@Override
public Object getChild(int groupPosition, int childPosition) {
return categoryName[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
@SuppressLint("ResourceAsColor")
public View getChildView(final int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) PointCategory_index.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(
R.layout.point_category_childview, null);
}
// View descriptionviewView=(RelativeLayout)
// convertView.findViewById(R.id.awardButton);
if (isLastChild) {
Log.d("TAG", "Last child");
}
final TextView awardTextView = (TextView) convertView
.findViewById(R.id.award);
awardTextView.setTextColor(getResources().getColor(
R.color.award_color));
awardTextView.setTypeface(font_regular);
// for(int i=0;i<)
/*
* TextView point = (TextView) convertView
* .findViewById(R.id.pointTextV); point.setText("Point");
*/
TextView pointValuetxt = (TextView) convertView
.findViewById(R.id.points);
pointValuetxt.setText(pointValue[groupPosition][childPosition]);
pointValuetxt.setTypeface(font_regular);
TextView pointInNumber = (TextView) convertView
.findViewById(R.id.pointTextV);
pointInNumber.setText(pointName[groupPosition][childPosition]);
pointInNumber.setTypeface(font_regular);
if (userTypeId.trim().equalsIgnoreCase("4")
|| userTypeId.trim().equalsIgnoreCase("1")) {
awardTextView.setVisibility(View.VISIBLE);
// check usertypeid
// set point category id
}
awardTextView.setOnClickListener(new OnClickListener() {
// int x=groupPosition;
@Override
public void onClick(View v) {
awardTextView.setTextColor(getResources().getColor(
R.color.green));
String id = EduInterface.pointIDArrayList
.get(groupPosition); // /Here change by dharma
// (categoryID->pointID)
Log.d("TAG", "Point Id test---->>>>>>" + id);
editor.putString("pointID", id);
/*
* Log.d("Click Point Id is", id);
* Log.d("Click Point Value is",
* EduInterface.pointValueArrayList.get(groupPosition));
*/
editor.commit();
if (userTypeId.trim().equalsIgnoreCase("1")) {
startActivity(new Intent(PointCategory_index.this,
ChildActivity.class));// Go to
// professor
// List
} else if (userTypeId.trim().equalsIgnoreCase("4")) {
Log.d("TAG", "Award Button was Clicked !!1");
startActivity(new Intent(PointCategory_index.this,
PointCategory_courseList.class));
}
}
});
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return categoryName[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return CategoriesIds.get(groupPosition);
}
@Override
public int getGroupCount() {
// return EduInterface.categoryIDArrayList.size();
return RemoveDuplicateCat.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) PointCategory_index.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(
R.layout.point_category_groupview, null);
}
TextView name = (TextView) convertView
.findViewById(R.id.categoryname);
// name.setText(EduInterface.categoryNameArrayList.get(groupPosition));
name.setText(RemoveDuplicateCat.get(groupPosition));
name.setTypeface(font_regular);
/*
* convertView.setOnClickListener(new OnClickListener() {
*
* @Override public void onClick(View v) { Log.d("TAG",
* "TEST->>"+RemoveDuplicateCat.get(groupPosition)); TextView name =
* (TextView) findViewById(R.id.categoryname);
* name.setText(RemoveDuplicateCat.get(groupPosition));
* name.setTypeface(font_regular); } });
*/
/*
* name.setOnClickListener(new View.OnClickListener() {
*
* @Override public void onClick(View v) { Log.d("TAG",
* "Clicking cATEEEE==="+RemoveDuplicateCat.get(groupPosition));
*
* } });
*/
// RemoveDuplicateCat
return convertView;
}
/*
* public boolean onChildClick(ExpandableListView parent, View v, int
* groupPosition, int childPosition, long id) { String test =
* (String)MyExpandableAdapter.getItem(groupPosition);
* Log.d("TAG","CLICK->"+test); // update the text view with the country
* return true; }
*/
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}