확장 가능한 목록보기의 아이에게 두 textviews을 추가하는 방법. 불행히도 스택 오버 플로우에서 발견 된 모든 솔루션과 Google 검색은 쓸데없는 것으로 판명되었습니다.내가 확장 목록보기에서 나란히 두 textviews 측을 배치하려고
이 링크는 비슷하지만 분명히하지 솔루션 adding two textViews to the header of the expandable listview
내가 원하는 것은 아이가 아닌 확장 가능한 목록의 헤더에 두 개의 텍스트 뷰를 배치하는 것입니다.
내가 두 개의 텍스트 뷰가 아이 뷰
ExpandableListAdapter.java
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> ParentItem;
private HashMap<String, List<String>> ChildItem;
public ExpandableListAdapter(Context context, List<String> ParentItem,
HashMap<String, List<String>> ChildItem) {
this.context = context;
this.ParentItem = ParentItem;
this.ChildItem = ChildItem;
}
@Override
public Object getChild(int listPosition, int expandedListPosition) {
return this.ChildItem.get(this.ParentItem.get(listPosition))
.get(expandedListPosition);
}
@Override
public long getChildId(int listPosition, int expandedListPosition) {
return expandedListPosition;
}
@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.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.child_item, null);
}
//TextView text1 = (TextView) convertView.findViewById(R.id.item1);
TextView text2 = (TextView) convertView.findViewById(R.id.item2);
//text1.setText("");
text2.setText(expandedListText);
return convertView;
}
@Override
public int getChildrenCount(int listPosition) {
return this.ChildItem.get(this.ParentItem.get(listPosition))
.size();
}
@Override
public Object getGroup(int listPosition) {
return this.ParentItem.get(listPosition);
}
@Override
public int getGroupCount() {
return this.ParentItem.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.context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.parent_item, null);
}
TextView listTitleTextView = (TextView) convertView
.findViewById(R.id.listTitle);
listTitleTextView.setTypeface(null, Typeface.BOLD);
listTitleTextView.setText(listTitle);
TextView location = (TextView) convertView
.findViewById(R.id.item1);
location.setTypeface(null, Typeface.BOLD);
location.setText("whatever you want");
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int listPosition, int expandedListPosition) {
return true;
}
public static HashMap<String, List<String>> getData() {
HashMap<String, List<String>> ParentItem = new HashMap<String,List<String>>();
List<String> NADMO = new ArrayList<String>();
NADMO.add("38838333");
NADMO.add("03220-34084");
NADMO.add("03820-23110");
NADMO.add("03222-22145");
NADMO.add("03120-46676");
NADMO.add("03720-23154");
NADMO.add("03920-22657");
NADMO.add("020-2006943/03620-27158");
NADMO.add("03321-32127");
NADMO.add("03520-27271");
List<String> GPS = new ArrayList<String>();
GPS.add("Lion");
GPS.add("Tiger");
GPS.add("Leopard");
GPS.add("Cheetah");
GPS.add("Bear");
List<String> TPS = new ArrayList<String>();
TPS.add("Cricket");
TPS.add("Football");
TPS.add("Tennis");
TPS.add("Basket Ball");
TPS.add("Base Ball");
ParentItem.put("NADMO"), NADMO);
ParentItem.put("GPS", GPS);
ParentItem.put("TPS", TPS);
return ParentItem;
}
}
MainActivity.java
public class CodeDir extends AppCompatActivity {
ExpandableListView expandableListView;
ExpandableListAdapter expandableListAdapter;
List<String> expandableListTitle;
HashMap<String, List<String>> expandableListDetail;
@Override
protected void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.activity_code_dir);
//TOOLBAR SUPPORT - Set a Toolbar to replace the ActionBar.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
actionBar.setDisplayHomeAsUpEnabled(true);
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
expandableListDetail = ExpandableListAdapter.getData();
expandableListTitle = new ArrayList<String>(expandableListDetail.keySet());
expandableListAdapter = new ExpandableListAdapter(this, expandableListTitle, expandableListDetail);
expandableListView.setAdapter(expandableListAdapter);
expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
expandableListTitle.get(groupPosition) + " ListView Open.",
Toast.LENGTH_SHORT).show();
}
});
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
expandableListTitle.get(groupPosition) + " ListView Closed.",
Toast.LENGTH_SHORT).show();
}
});
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(getApplicationContext(),
expandableListDetail.get(
expandableListTitle.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT
)
.show();
return false;
}
});
}
}
에처럼 보이게하는 방법의
이미지
이 도움이 될 child_item.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="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:padding="2dp">
<TextView
android:id="@+id/item1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingTop="10dp"
android:layout_weight="1.0"
android:paddingBottom="10dp"
android:text="Left Side"
android:textSize="20sp"/>
<TextView
android:id="@+id/item2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingTop="10dp"
android:layout_weight="1.0"
android:paddingBottom="10dp"
android:text="Right side"
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
어떻게 지금 찾고있다? 현재 스크린 샷을 추가 하시겠습니까? –
예를 @SohailZahid하지만 확장리스트의 아이에 –