mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-20 22:26:54 +01:00
populate study list, doing the sorting in the DB query for now
This commit is contained in:
parent
3f8e456db2
commit
42f35cb3d9
3 changed files with 79 additions and 17 deletions
|
@ -15,11 +15,11 @@
|
||||||
android:drawSelectorOnTop="true"
|
android:drawSelectorOnTop="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ExpandableListView android:id="@id/android:list"
|
<ListView android:id="@id/android:list"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:drawSelectorOnTop="false"
|
android:drawSelectorOnTop="false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -1607,6 +1607,33 @@ public class DBUtils {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] studyListWords( Context context, int lang )
|
||||||
|
{
|
||||||
|
String[] result = null;
|
||||||
|
String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang );
|
||||||
|
String[] columns = { DBHelper.WORD };
|
||||||
|
String orderBy = DBHelper.WORD;
|
||||||
|
|
||||||
|
initDB( context );
|
||||||
|
synchronized( s_dbHelper ) {
|
||||||
|
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||||
|
Cursor cursor = db.query( DBHelper.TABLE_NAME_STUDYLIST, columns,
|
||||||
|
selection, null, null, null, orderBy );
|
||||||
|
int count = cursor.getCount();
|
||||||
|
result = new String[count];
|
||||||
|
if ( 0 < count ) {
|
||||||
|
int index = 0;
|
||||||
|
int colIndex = cursor.getColumnIndex( DBHelper.WORD );
|
||||||
|
while ( cursor.moveToNext() ) {
|
||||||
|
result[index++] = cursor.getString(colIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static void copyGameDB( Context context, boolean toSDCard )
|
private static void copyGameDB( Context context, boolean toSDCard )
|
||||||
{
|
{
|
||||||
String name = DBHelper.getDBName();
|
String name = DBHelper.getDBName();
|
||||||
|
|
|
@ -25,9 +25,14 @@ import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
|
|
||||||
public class StudyList extends XWListActivity {
|
public class StudyList extends XWListActivity
|
||||||
private Spinner mSpinner;
|
implements OnItemSelectedListener {
|
||||||
|
|
||||||
|
private Spinner m_spinner;
|
||||||
|
private int[] m_langCodes;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate( Bundle savedInstanceState )
|
protected void onCreate( Bundle savedInstanceState )
|
||||||
|
@ -36,17 +41,18 @@ public class StudyList extends XWListActivity {
|
||||||
|
|
||||||
setContentView( R.layout.studylist );
|
setContentView( R.layout.studylist );
|
||||||
|
|
||||||
mSpinner = (Spinner)findViewById( R.id.pick_language );
|
m_spinner = (Spinner)findViewById( R.id.pick_language );
|
||||||
int[] langs = DBUtils.studyListLangs( this );
|
m_langCodes = DBUtils.studyListLangs( this );
|
||||||
if ( 0 == langs.length ) {
|
if ( 0 == m_langCodes.length ) {
|
||||||
finish();
|
finish();
|
||||||
} else if ( 1 == langs.length ) {
|
} else if ( 1 == m_langCodes.length ) {
|
||||||
mSpinner.setVisibility( View.GONE );
|
m_spinner.setVisibility( View.GONE );
|
||||||
|
loadList( m_langCodes[0] );
|
||||||
} else {
|
} else {
|
||||||
String[] names = DictLangCache.getLangNames( this );
|
String[] names = DictLangCache.getLangNames( this );
|
||||||
String[] myNames = new String[langs.length];
|
String[] myNames = new String[m_langCodes.length];
|
||||||
for ( int ii = 0; ii < langs.length; ++ii ) {
|
for ( int ii = 0; ii < m_langCodes.length; ++ii ) {
|
||||||
myNames[ii] = names[langs[ii]];
|
myNames[ii] = names[m_langCodes[ii]];
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAdapter<String> adapter = new
|
ArrayAdapter<String> adapter = new
|
||||||
|
@ -55,13 +61,42 @@ public class StudyList extends XWListActivity {
|
||||||
myNames );
|
myNames );
|
||||||
adapter.setDropDownViewResource( android.R.layout.
|
adapter.setDropDownViewResource( android.R.layout.
|
||||||
simple_spinner_dropdown_item );
|
simple_spinner_dropdown_item );
|
||||||
mSpinner.setAdapter( adapter );
|
m_spinner.setAdapter( adapter );
|
||||||
|
m_spinner.setOnItemSelectedListener( this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////
|
||||||
|
// AdapterView.OnItemSelectedListener interface
|
||||||
|
//////////////////////////////////////////////////
|
||||||
|
public void onItemSelected( AdapterView<?> parent, View view,
|
||||||
|
int position, long id )
|
||||||
|
{
|
||||||
|
int lang = m_langCodes[position];
|
||||||
|
loadList( lang );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onNothingSelected( AdapterView<?> parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadList( int lang )
|
||||||
|
{
|
||||||
|
String[] words = DBUtils.studyListWords( this, lang );
|
||||||
|
ArrayAdapter<String> adapter = new ArrayAdapter<String>
|
||||||
|
( this, android.R.layout.simple_list_item_1 );
|
||||||
|
for ( String word : words ) {
|
||||||
|
adapter.add( word );
|
||||||
|
}
|
||||||
|
// adapter.sort();
|
||||||
|
|
||||||
|
setListAdapter( adapter );
|
||||||
|
}
|
||||||
|
|
||||||
public static void launch( Context context )
|
public static void launch( Context context )
|
||||||
{
|
{
|
||||||
Intent intent = new Intent( context, StudyList.class );
|
Intent intent = new Intent( context, StudyList.class );
|
||||||
context.startActivity( intent );
|
context.startActivity( intent );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue