私はExpandableListAdapter
を初めて使用しています。 groupViewにはtextviewsが、childViewにはいくつかのボタンがあります。私はインターネットから次のコードを使用し、私の好みに応じてそれを変換しようとしました。しかし、getGroupCount()
メソッドには問題があります。私のコード内で知っている_listDataHeader
と_listDataChild
はnullですが、代わりに何を使うべきですか?ここに私のヘッダビュー私のケースではExpandableListAdapterメソッドが正しく動作しません。 ExpandableListViewの代わりに
and Child View layout
この子のビューを画面上に表示する必要があります。このデザインの正しいAndroidビューを使用していますか?
public class ExpandableListAdapter extends BaseExpandableListAdapter {
Activity context;
ArrayList<String> s_date,c_number,d_ration,s_time,download_path,a_number,a_name;
String id[];
String mUrl;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Activity context, ArrayList<String> start_date, ArrayList<String> caller_number, ArrayList<String> duration,ArrayList<String> start_time, ArrayList<String> download_path, ArrayList<String> agent_number, ArrayList<String> agent_name) {
this.context=context;
this.s_date=start_date;
this.c_number=caller_number;
this.d_ration=duration;
this.s_time=start_time;
this.download_path=download_path;
this.a_number=agent_number;
this.a_name=agent_name;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
Button play_button=(Button) convertView.findViewById(R.id.play);
play_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("play child is",childText);
}
});
Button download_button=(Button) convertView.findViewById(R.id.download);
download_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("download child is",childText);
}
});
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this.s_date.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView start_date = (TextView) convertView.findViewById(R.id.start_date);
start_date.setText(s_date.get(groupPosition));
TextView caller_number = (TextView) convertView.findViewById(R.id.caller_number);
caller_number.setText(c_number.get(groupPosition));
TextView duration = (TextView) convertView.findViewById(R.id.duration);
duration.setText(d_ration.get(groupPosition));
TextView start_time = (TextView) convertView.findViewById(R.id.start_time);
start_time.setText(s_time.get(groupPosition));
TextView agent_name = (TextView) convertView.findViewById(R.id.agent_name);
agent_name.setText(a_name.get(groupPosition));
TextView agent_number = (TextView) convertView.findViewById(R.id.agent_number);
agent_number.setText(a_number.get(groupPosition));
// start_date.setTypeface(null, Typeface.BOLD);
// start_date.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
を助け、これは私がカスタムリストビューを使用していて、その中で私が目に見えるなくなっメソッドを使用しているか@PratikDasaにより示唆されるように、私は特殊なアダプタ
ExpandableListAdapter a=new ExpandableListAdapter(MainScreen.this,start_date,caller_number,duration,start_time,download_path,agent_number,agent_name);
data_list.setAdapter(a);
ここでは、ヘッダーと子アイテムを設定していますか? – Noorul
ヘッダーは単一のアイテムでなければならず、子ビューは複数のアイテムであることがあります。あなたの子アイテムのキーにヘッダーIDを使用する必要があります。 thats all – Noorul
私はヘッダーのレイアウトと子@Ahamedの別のレイアウトがあります。このコードでは_listDataHeaderと_listDataChildがnullであることがわかりますが、私のコードによれば、それらの代わりに何を設定すればよいですか? –