2016-10-22 12 views
0

SQLiteデータベース(厳密には3列)からデータを取得し、展開可能リストビューの子として表示できます。しかし、私はそれらを表示するよう:SQLiteデータベースのデータを、さまざまなtextviewsで子要素としてExpandable ListViewに表示する方法

期限:2016年10月23日

後半サブ:YES

ペナルティ:

10%以上、左側のテキスト、Iから表示していますテキストビューのテキスト(Child xml)とコロンの後の右側のテキストは、データベースから取得しています。

アダプタのgetChildViewメソッドでこれを処理するにはどうすればよいですか?ここで

は私のアダプタクラスのコードです:ここで

public class AssignmentDisplayAdapter extends BaseExpandableListAdapter{ 
private Context mContext; 
private List<String> expandableListTitle; 
private HashMap<String, List<CourseDisplay>> expandableListDetail; 
private LayoutInflater mInflater; 

public AssignmentDisplayAdapter(Context context, List<String> expandableListTitle, 
           HashMap<String, List<CourseDisplay>> expandableListDetail) { 

    this.mContext = context; 
    this.expandableListTitle = expandableListTitle; 
    this.expandableListDetail = expandableListDetail; 
    mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
} 

@Override 
public Object getChild(int listPosition, int expandedListPosition) { 
    return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)) 
      .get(expandedListPosition); 
} 

@Override 
public long getChildId(int listPosition, int expandedListPosition) { 
    return expandedListPosition; 
} 

@Override 
public boolean hasStableIds() { 
    return false; 
} 

@Override 
public View getChildView(int listPosition, final int expandedListPosition, 
         boolean isLastChild, View convertView, ViewGroup parent) { 
    final String expandedListText = (String) getChild(listPosition, expandedListPosition); 
    if (convertView == null) { 
     LayoutInflater layoutInflater = (LayoutInflater) this.mContext 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = layoutInflater.inflate(R.layout.custom_listview_expandable_child, null); 
    } 
    TextView expandedListTextView = (TextView) convertView 
      .findViewById(R.id.assign_duedate_display); 
    expandedListTextView.setText(expandedListText); 
    return convertView; 
} 

@Override 
public int getChildrenCount(int listPosition) { 
    return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)) 
      .size(); 
} 

@Override 
public Object getGroup(int listPosition) { 
    return this.expandableListTitle.get(listPosition); 
} 

@Override 
public int getGroupCount() { 
    return this.expandableListTitle.size(); 
} 

@Override 
public long getGroupId(int listPosition) { 
    return listPosition; 
} 

@Override 
public View getGroupView(int listPosition, boolean isExpanded, 
         View convertView, ViewGroup parent) { 
    String listTitle = (String) getGroup(listPosition); 
    if (convertView == null) { 
     LayoutInflater layoutInflater = (LayoutInflater) this.mContext. 
       getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = layoutInflater.inflate(R.layout.custom_listview_expandable_parent, null); 
    } 
    TextView listTitleTextView = (TextView) convertView 
      .findViewById(R.id.parent_text); 
    listTitleTextView.setTypeface(null, Typeface.BOLD); 
    listTitleTextView.setText(listTitle); 
    return convertView; 
} 


@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return false; 
} 
}//end class 

は私の親のXMLコードである:ここで

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:id="@+id/parent_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
     android:textColor="@color/primary" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp"/> 

</LinearLayout> 

は私の子供のXMLコードです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    <TextView 
     android:id="@+id/assign_duedatetext_display" 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:text="Due Date: " 
     android:layout_weight="3" 
     android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp"/> 

    <TextView 

     android:id="@+id/assign_duedate_display" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_toRightOf="@id/assign_duedatetext_display" 
     android:layout_marginLeft="16dp" 
     android:textColor="@color/primary" 
     android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:id="@+id/assign_latesubtext_display" 
      android:layout_width="150dp" 
      android:layout_height="wrap_content" 
      android:text="Late Submission: " 
      android:layout_weight="3" 
      android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" 
      android:paddingTop="10dp" 
      android:paddingBottom="10dp"/> 

     <TextView 

      android:id="@+id/assign_latesub_display" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_toRightOf="@id/assign_latesubtext_display" 
      android:layout_marginLeft="16dp" 
      android:textColor="@color/primary" 
      android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" 
      android:paddingTop="10dp" 
      android:paddingBottom="10dp"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:id="@+id/assign_penaltytext_display" 
      android:layout_width="150dp" 
      android:layout_height="wrap_content" 
      android:text="Penalty: " 
      android:layout_weight="3" 
      android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" 
      android:paddingTop="10dp" 
      android:paddingBottom="10dp"/> 

     <TextView 

      android:id="@+id/assign_penalty_display" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_toRightOf="@id/assign_penaltytext_display" 
      android:layout_marginLeft="16dp" 
      android:textColor="@color/primary" 
      android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" 
      android:paddingTop="10dp" 
      android:paddingBottom="10dp" /> 
    </RelativeLayout> 
</LinearLayout> 

私は何かのニーズを信じますgetChildViewメソッドで実行されますが、これをどのように処理するかは不明です。これで私を導いてください。

+0

最も簡単な方法は垂直に配置された二つのサブレイアウトからなるレイアウトのように各列を考えることである。

はここ法)getChildView(更新されます。上のレイアウトは "ヘッダ"、下のレイアウトはTextViewsを含みます。下のレイアウトは表示されませんが、ユーザーが上のレイアウトをクリックしたときに表示されます。これを行うには、一番上の行にonClickListenerを設定し、その内部の下のビューの可視性を変更します。可視性を変更するには、View.setVisibility(int visibility)メソッド – Vektor88

+0

を使用します。これを試してみます。コメントありがとう – Venkata

+0

私は自分の答えを掲載しました。私は、コード内のテキストを動的に更新する方法を見つけました。とにかく私はあなたの提案を試してみましょう。御時間ありがとうございます。 – Venkata

答えて

0

私はデータベース内のデータ形式が各親に対して同じになることを知っているので、これを動的に達成することができます。これを達成する

@Override 
public View getChildView(int listPosition, final int expandedListPosition, 
         boolean isLastChild, View convertView, ViewGroup parent) { 

    String expandedListText = (String) getChild(listPosition, expandedListPosition); 


    if (convertView == null) { 
     LayoutInflater layoutInflater = (LayoutInflater) this.mContext 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = layoutInflater.inflate(R.layout.custom_listview_expandable_child, null); 
    } 
    TextView expandedListTextView1 = (TextView) convertView 
      .findViewById(R.id.assign_duedate_display); 

    TextView expandedListTextView2 = (TextView) convertView 
      .findViewById(R.id.assign_duedatetext_display); 


    if (expandedListPosition == 0){ 
     expandedListTextView2.setText("Due date: "); 
    }else if(expandedListPosition == 1){ 
     expandedListTextView2.setText("late submission: "); 
    }else { 
     expandedListTextView2.setText("Penalty: "); 
    } 
    expandedListTextView1.setText(expandedListText); 

    return convertView; 
} 
関連する問題