2013-05-17 15 views
0

我有问题。我在Java/Android编程列表适配器。我重写返回View的方法(它是Clicked项目的消耗性列表视图)。问题是:Java - TextView引用另一个TextView在可消耗列表视图中儿童

Log.i显示我:

  • 05-17 14:04:50.494:I/createTextView(21790):0 06萨拉梅
  • 05-17 14:04: 50.504:I/createTextView(21790):1个11培根

但TextViews看起来既:

  • 111培根
  • 1 11 Pancetta

它看起来像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

我想用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; 
} 
+0

它不会显示任何东西。 TextView - > tv - >在引用R.id.SomeTextView;时似乎为null。当我试图制作我的TextView时,它是空白的。 – boski

+0

你膨胀了哪个布局?你是否夸大了团队布局? – Opiatefuchs

相关问题