我的应用程序中有一个基本的(有效的)expandableListView,其中包含2个组和每个组内的2个孩子(以我的人名)。
现在,我想在姓名旁边第二列,其中包含该人的电话号码。最终,我想在包含电话号码的第二列上建立到电话的自动链接。
希望我能得到帮助。
我想存档的示例
[在此处输入图片描述] [1]
我的ExpendableListViewAdapter
public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
String[] groupNames = {“Group 1", “Group 2”};
String[][] childNames = {
// Group 1
{“Name 1”, “Name 2”},
// Group 2
{“Name 1”, “Name 2”},
};
Context context;
public ExpandableListViewAdapter(Context context) {
this.context = context;
}
@Override
public int getGroupCount() {
return groupNames.length;
}
@Override
public int getChildrenCount(int groupPosition) {
return childNames[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return groupNames[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return childNames[groupPosition][childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View view, ViewGroup parent) {
TextView txtView = new TextView(context);
txtView.setText(groupNames[groupPosition]);
txtView.setPadding(150, 40, 0, 40);
txtView.setTextColor(Color.rgb(2, 20, 94));
txtView.setTextSize(23);
return txtView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
final TextView txtView = new TextView(context);
txtView.setText(childNames[groupPosition][childPosition]);
txtView.setPadding(100, 40, 0, 40);
txtView.setTextColor(Color.rgb(2, 20, 94));
txtView.setTextSize(18);
txtView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, txtView.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
return txtView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
我的布局活动
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.nav.PhonenumbersActivity"
android:orientation="vertical"
android:background="@drawable/bg_main">
<TextView
style="@style/text_question"
android:text="Telefoonnummers"
android:layout_gravity="center"
android:layout_margin="25dp"
android:textSize="30dp"/>
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
</ExpandableListView>
</LinearLayout>
[1]: https://i.stack.imgur.com/5kV7Y.png