2

ListView에서 한 국가의 언어를 나열하는 클래스를 구현하고 있습니다. 바로 아래에 그룹 제목 및 해당 언어의 모든 버전이 하위 항목 인 주요 언어가 포함 된 ExpandableListView가 있습니다.ListView는 그 아래에있는 모든 것을 포함합니다.

현재 데이터는 올바르게 채워지지만 목록보기는 구분선과 ExpandableListView 위에 표시됩니다. 사용자가 두 목록의 높이를 정적으로 정의하지 않고 두 목록의 모든 항목을 스크롤 할 수있게하려고합니다. 현재 ListView에 더 많은 항목이있는 경우 한 화면에 표시하면 목록보기와 그 위에있는 항목 만 표시되고 ExpandableListView를 덮습니다.

language_list.xml :

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


<EditText android:id="@+id/search_box" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="type to filter list" 
    android:inputType="text" 
    android:layout_alignParentTop = "true" 
    android:maxLines="1"/> 

<TextView 
    android:id="@+id/languages" 
    android:text="Locatoin Languages" 
    android:background="#fff" 
    android:textColor="#000" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_below="@id/search_box" 
    android:textAppearance="?android:attr/textAppearanceSmall"> 
</TextView> 

<ListView 
    android:id="@+id/expandableLanguage" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/languages" 
    android:drawSelectorOnTop="false"> 
</ListView> 

<TextView 
    android:id="@+id/majorLanguages" 
    android:text="Major Languages" 
    android:background="#fff" 
    android:textColor="#000" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_below="@id/expandableLanguage" 
    android:textAppearance="?android:attr/textAppearanceSmall"> 
</TextView> 

<ExpandableListView 
    android:id="@+id/expandableMajorLanguage" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/majorLanguages"> 
</ExpandableListView> 

<requestFocus></requestFocus> 
</LinearLayout> 

LanguageList.Java

public class LanguageList extends Activity { 
private static LocalSQLiteHelper dbHelper; 
private static SQLiteDatabase db; 
private static String BASE_LANGUAGE_SELECTOR = ""; 
private static String GET_MAJOR_LANGUAGES_BY_MACRO = ""; 
private static String GET_MAJOR_LANGUAGES_BY_ISO = ""; 
private static String GET_MAJOR_LANGUAGES_TITLES = ""; 

ExpandableListAdapter adapterExpandable; 
ListAdapter adapterList; 

String locationName, locationID, languageName; 
private ArrayList<LanguageDataType> LocationLanguages = new ArrayList<LanguageDataType>(); 
private ArrayList<LanguageDataType> majorLanguagesTitles = new ArrayList<LanguageDataType>(); 
private ArrayList<ArrayList<LanguageDataType>> majorLanguages = new ArrayList<ArrayList<LanguageDataType>>(); 
private ExpandableListView languageLV ; 
private ListView locationLV; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.language_list); 
    setTitle("Select Languages"); 
    dbHelper = new LocalSQLiteHelper(this.getBaseContext()); 
    db = dbHelper.getReadableDatabase(); 

    Bundle locationData = getIntent().getExtras(); 

    locationName = locationData.getString("locationName"); 
    locationID = locationData.getString("locationID"); 


    getLocationData(); 
    getMajorLanguageData(); 




    languageLV=(ExpandableListView) findViewById(R.id.expandableMajorLanguage); 
    languageLV.getAdapter(); 
    adapterExpandable=new LanguageExpandableAdapter(this, majorLanguagesTitles, majorLanguages); 
    languageLV.setAdapter(adapterExpandable); 


    locationLV= (ListView) findViewById(R.id.expandableLanguage); 
    locationLV.getAdapter(); 
    adapterList=new LanguageListAdapter(this, LocationLanguages); 
    locationLV.setAdapter(adapterList); 

} 

private void getLocationData(){ 
    //locationTitle.clear(); 
    TextView text = (TextView) findViewById(R.id.languages); 
    text.setText("Languages spoken in " +locationName); 

    LocationLanguages.clear(); 
    //locationTitle.add(new LanguageDataType("Languages spoken in " +locationName, null, null)); 
    Cursor row = null; 
    row = db.rawQuery(BASE_LANGUAGE_SELECTOR + locationID + "';", null); 

    if((row.getCount() > 0) && (!row.isClosed())){ 
     row.moveToFirst(); 
     do{ 
      LocationLanguages.add(new LanguageDataType(row.getString(0), row.getString(1),row.getString(2))); 
     }while(row.moveToNext()); 
     row.close();    
    } 
} 



private void getMajorLanguageData(){ 
    majorLanguagesTitles.clear(); 
    majorLanguages.clear(); 

    Cursor row = null; 
    row = db.rawQuery(GET_MAJOR_LANGUAGES_TITLES, null); 

    if((row.getCount() > 0) && (!row.isClosed())){ 
     row.moveToFirst(); 
     do{ 
      majorLanguagesTitles.add(new LanguageDataType(row.getString(0), row.getString(1),row.getString(2))); 

      if(row.getString(2)==null){ 
       queryLanguages(GET_MAJOR_LANGUAGES_BY_ISO + row.getString(1) + "';", majorLanguages); 
      } else { 
       queryLanguages(GET_MAJOR_LANGUAGES_BY_MACRO + row.getString(2) + "';", majorLanguages); 
      }   
     }while(row.moveToNext()); 
     row.close();    
    } 
} 

private void queryLanguages(String sql,ArrayList<ArrayList<LanguageDataType>> inputList) {  

    Cursor row = null; 
    row = db.rawQuery(sql, null); 
    ArrayList<LanguageDataType> languageList = new ArrayList<LanguageDataType>(); 

    if((row.getCount() > 0) && (!row.isClosed())){ 
     row.moveToFirst(); 
     do{ 
      languageList.add(new LanguageDataType(row.getString(0), row.getString(1),row.getString(2))); 
     }while(row.moveToNext()); 
     row.close();    
    } 
    inputList.add(languageList); 
} 

나는 두 개의 어댑터 ExpandableListView에 대한 ListView 다른 하나는 다른 있습니다.

LanguageExpandableAdapter.java

public class LanguageExpandableAdapter extends BaseExpandableListAdapter{ 
Context mContext; 
private ArrayList<LanguageDataType> titles = new ArrayList<LanguageDataType>(); 
private ArrayList<ArrayList<LanguageDataType>> languages = new ArrayList<ArrayList<LanguageDataType>>(); 


public LanguageExpandableAdapter(Context context, ArrayList<LanguageDataType> inputTitles, ArrayList<ArrayList<LanguageDataType>> inputLanguages) { 
    mContext = context; 

    for (LanguageDataType value: inputTitles) { 
     titles.add(value); 
    } 

    for (ArrayList<LanguageDataType> value: inputLanguages) { 
     languages.add(value); 
    } 

} 

public Object getChild(int groupPosition, int childPosition) { 
    return languages.get(groupPosition).get(childPosition).getLocationName(); 
} 

public long getChildId(int groupPosition, int childPosition) { 
    return childPosition; 
} 

public int getChildrenCount(int groupPosition) { 
    return languages.get(groupPosition).size(); 
} 

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
     View convertView, ViewGroup parent) { 
    TextView childeTitle = null; 
    LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v = null; 
    v = layoutInflater.inflate(R.layout.custom_language_child_row, null); 
    childeTitle = (TextView) v.findViewById(R.id.text_element); 
    String myText = this.getChild(groupPosition, childPosition).toString(); 
    childeTitle.setText(myText); 

    return v; 

} 

public Object getGroup(int groupPosition) { 
    return titles.get(groupPosition).getLocationName(); 
} 

public int getGroupCount() { 
    return titles.size(); 
} 

public long getGroupId(int groupPosition) { 
    return groupPosition; 
} 

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, 
     ViewGroup parent) { 

    TextView groupTitle = null; 
    LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v = null; 
    v = layoutInflater.inflate(R.layout.custom_language_group_row, null); 
    groupTitle = (TextView) v.findViewById(R.id.text_element); 
    String myText = this.getGroup(groupPosition).toString(); 
    groupTitle.setText(myText); 

    return v; 
} 

public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return true; 
} 

public boolean hasStableIds() { 
    return true; 
} 

LanguageListAdapter.java

public class LanguageListAdapter extends BaseAdapter { 

private Activity activity; 
List<LanguageDataType> language = new ArrayList<LanguageDataType>(); 
List<LanguageDataType> origLocation = new ArrayList<LanguageDataType>(); 

private static LayoutInflater inflater=null; 



public LanguageListAdapter(Activity listActivity, List<LanguageDataType> LanguageList) { 
    activity = listActivity; 

    for (LanguageDataType value: LanguageList) { 
     language.add(value); 
    } 

    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
} 


public int getCount() { 
    return language.size(); 
} 

public Object getItem(int position) { 
    return position; 
} 

public long getItemId(int position) { 
    return position; 
} 


public View getView(int position, View convertView, ViewGroup parent) { 
    View vi=convertView; 
    if(convertView==null){ 
     vi = inflater.inflate(R.layout.custom_language_child_row, null); 
    } 

    TextView text=(TextView)vi.findViewById(R.id.text_element); 
    text.setText(language.get(position).getLocationName()); 

    return vi; 
} 

public Filter getFilter() { 
    return null; 
} 

아무도 내가 ListView를 통해 내 extendableListView을에 지속적 스크롤을 할 수있는 방법 어떤 제안이있는 경우 나는 거리다. 많이 감사드립니다.

답변

0

먼저 화면 맨 아래에 정렬 된 ExpandableListView를 정의한 다음 Listview를 ExpandableListView 위에 정의하십시오.

+0

ExpandableListView가 표시되지만 ListView가 더 이상 표시되지 않습니다. 데이터가 올바르게 채워 졌는지 확인했습니다. – jburkett

0

두 가지 방법으로 화면을 분할하는 방법은 두 가지 스크롤 가능한 항목을 스크롤하는 방법을 알지 못합니다.

일반 목록보기가 두 개인 경우 해결책을 찾을 수 있지만 listview와 확장 목록보기는 해당 솔루션에서 작동하지 않습니다.

내가 가지고 올 수있는 최선 포함하도록 XML에 두 개의 목록보기 정의를 변경하는 것입니다 :

android:layout_height="0dp" 
android:layout_weight="1" 

그들 사이의 화면을 splict 화면에 둘을 유지하도록 원인이있다.

관련 문제