2

ListView で国の言語を一覧表示するクラスを実装しています。そのすぐ下に、グループ タイトルに主要な言語があり、その言語のすべてのバージョンが子として含まれる ExpandableListView があります。

現在、データは正しく入力されていますが、リスト ビューは仕切りと ExpandableListView の上に表示されます。両方のリストの高さを静的に定義しなくても、ユーザーが両方のリストのすべてのアイテムをスクロールできるようにしたいと考えています。現在、ListView に複数の項目があり、1 つの画面に表示されると、リスト ビューとその上の項目のみが表示され、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);
}

ListView用と用の 2 つのアダプターがありExpandableListViewます。

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;
}

継続的にスクロールする方法について何か提案があればListViewextendableListViewよろしくお願いします。

4

2 に答える 2

0

最初に ExpandableListView を定義し、画面の下部に配置してから、Listview を ExpandableListView の上に定義してみてください。

于 2012-06-15T13:07:33.883 に答える