2015-04-10 2 views
0

У меня есть expandableListview, который отлично работает, но теперь в childview я должен сделать его больше и добавить больше информации в том смысле, что мне нужно добавить больше текстового представления, соответствующего каждому дочернему элементу по вертикали. Например, макет для зрения ребенка должен быть что-то вроде этогоДобавление текстового представления в макет детского просмотра ExpandableListView

Type 1  Value1 
Type 2  Value2 
Type 3  Value3 

Category  Average 

У меня уже есть эта категория и среднее, но теперь нужен подтипы и соответствующих значения.

Для этого я пытаюсь раздуть новый макет, имеющий два текстовых поля, а затем добавить к дочернему виду. но это больше, чем притирая информацию, которую я не знаю, как сделать ее вертикальной. Я делюсь куском кода, который пытается это сделать.

@Override 
public View getChildView(int groupPosition, final int childPosition, 
         boolean isLastChild, View convertView, ViewGroup parent) 
{ 
    holder = new ViewHolder(); 
    if (convertView == null) 
    { 
     holder = new ViewHolder(); 
     convertView = layoutInflater.inflate(R.layout.list_item, null); 
     holder.sub_rl = (RelativeLayout) convertView.findViewById(R.id.sub_row_layout); 
     holder.cat = (TextView) convertView.findViewById(R.id.sub_row_cat); 
     holder.avg = (TextView) convertView.findViewById(R.id.sub_row_avg); 
     convertView.setTag(R.id.sub_row_layout, holder.sub_rl); 
     convertView.setTag(R.id.sub_row_cat, holder.cat); 
     convertView.setTag(R.id.sub_row_avg, holder.avg); 
     convertView.setTag(holder); 
    } 

    else 
     if (getChild(groupPosition, childPosition).type.equals("Emp")) { 

        for(int i = 0; i < 5; i ++){ 
         Log.d(TAG, "coming "); 
         LayoutInflater inflater2 = null; 
         inflater2 = (LayoutInflater) mContext.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
         View mLinearView2 = inflater2.inflate(R.layout.type_layout, null); 
         LinearLayout wifi_layout = (LinearLayout) mLinearView2.findViewById(R.id.type_layout); 
         TextView mSubItemName = (TextView) mLinearView2.findViewById(R.id.row_type); 
         TextView sub_value = (TextView) mLinearView2.findViewById(R.id.row_value); 
         mSubItemName.setText("Sub Text "+ i); 
         holder.sub_rl.addView(wifi_layout); 

        } 

        if (getChild(groupPosition, childPosition).cat.isEmpty()) { 
         if (getChild(groupPosition, childPosition).cat != null && holder.cat != null) 
          holder.cat.setText("(Hidden Category)"); 
        } else { 
         if (getChild(groupPosition, childPosition).cat != null && holder.cat != null) 
          holder.cat.setText(getChild(groupPosition, childPosition).cat); 
        } 
        if (getChild(groupPosition, childPosition).avg != null && holder.avg != null) 
         holder.avg.setText(getChild(groupPosition, childPosition).avg); 
return convertView; 
} 

list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="55dip" 
android:id="@+id/es_child_main" 
android:layout_marginLeft="10dp" 
android:orientation="vertical" > 
<RelativeLayout 
    android:id="@+id/sub_row_layout" 
    android:layout_width="wrap_content" 
    android:layout_marginLeft="15dp" 
    android:layout_marginTop="5dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginBottom="5dp" 
    android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/sub_row_cat" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="20dp" 
    android:layout_marginTop="8dp" 
    android:textColor="#ffffff" 
    android:layout_marginLeft="10dp" 
    /> 
<TextView 
    android:id="@+id/sub_row_avg" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/sub_row_cat" 
    android:textSize="15dp" 
    android:textColor="#ffffff" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="5dp"/> 
    </RelativeLayout> 
    </RelativeLayout> 

любое предложение было бы неплохо ... или лучше подход Благодаря

+0

Опубликовать свой list_item.xml код – Harry

+0

обновил вопрос m –

ответ

0

То, что я предлагаю использовать линейный макет или лучше макет таблицы для Вашей потребности ребенка макета, как это, он работает для меня:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Type 1" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:text="Value 1" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Type 2" /> 

     <TextView 
      android:id="@+id/textView4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:text="Value 2" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Type 3" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:text="Value 3" /> 
    </TableRow> 

</TableLayout> 
+0

но я не понимаю, почему я должен использовать табличный макет для моего основного макета, который является list_item? \ –

+0

Чтобы получить результат, как вы разместили ниже строки «Например, макет для дочернего представления должен быть чем-то вроде этого». Если я не ошибаюсь, вы хотите, чтобы три строки в одном дочернем представлении правильно? – Harry

Смежные вопросы