我有疑问。我在Java / Android中编写List Adapter。我重写了返回View的方法(它是Clicked项目中的消耗列表视图)。问题是:
Log.i告诉我:
但TextViews看起来都是:
看起来TextView引用了最后一个TextView。如何解决?
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Log.e("SecondLevelAdapter", "getGroupView");
TextView tv = new TextView(OrderFirstGridPage.this);
if((myArrayProductList.get(groupPosition).get(0).getFlgZlozony() == 1)) {
Log.i("createTextView", String.valueOf(counterProductName)+" "+myArrayProductList.get(groupPosition).get(counterProductName).toString());
tv.setText(myArrayProductList.get(groupPosition).get(counterProductName).toString());
counterProductName++;
}
tv.setPadding(22, 7, 7, 7);
tv.setGravity(Gravity.LEFT);
tv.setTextAppearance(OrderFirstGridPage.this, R.style.TextLarge);
tv.setTextSize(25);
return tv;
}
答案 0 :(得分:0)
我认为使用LayoutInflater会更好:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
if (convertView == null) {
LayoutInflater inf = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.yourLayout, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.yourTextViewId);
if((myArrayProductList.get(groupPosition).get(0).getFlgZlozony() == 1)) {
Log.i("createTextView", String.valueOf(counterProductName)+" "+myArrayProductList.get(groupPosition).get(counterProductName).toString());
tv.setText(myArrayProductList.get(groupPosition).get(counterProductName).toString());
counterProductName++;
}
tv.setPadding(22, 7, 7, 7);
tv.setGravity(Gravity.LEFT);
tv.setTextAppearance(OrderFirstGridPage.this, R.style.TextLarge);
tv.setTextSize(25);
return convertView;
}