public
class
MainActivity
extends
Activity {
public
static
final
String TAG =
"DictionaryInfoView"
;
EditText editSearch;
DataListView listView;
IconTextListAdapter adapter;
Button btnSearch;
String strSearch;
InputMethodManager imm;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
editSearch = (EditText) findViewById(R.id.editText);
btnSearch = (Button) findViewById(R.id.searchView);
btnSearch.setOnClickListener(
new
View.OnClickListener() {
public
void
onClick(View v) {
strSearch = editSearch.getText().toString();
Intent intent =
new
Intent(MainActivity.
this
, SecondActivity.
class
);
intent.putExtra(
"strSearch"
,strSearch.length());
startActivity(intent);
}
});
};
}
이것은 두번째 액티비티
public
class
SecondActivity
extends
Activity {
public
static
final
String TAG =
"SecondActivity"
;
DataListView listView;
IconTextListAdapter adapter;
InputMethodManager imm;
String strSearch2;
String strSearchQuery;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.listview);
Intent intent = getIntent();
strSearch2 = intent.getStringExtra(
"strSearch"
);
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
adapter =
new
IconTextListAdapter(
this
);
listView =
new
DataListView(
this
);
LinearLayout linLayout = (LinearLayout) findViewById(R.id.LayoutDicList);
linLayout.addView(listView);
strSearchQuery = strSearch2.concat(
"%"
);
DatabaseHelper.openDatabase(DatabaseHelper.wordDatabaseFile);
Cursor cursor = DatabaseHelper.queryMasterTable(strSearchQuery);
AddCursorData(cursor);
listView.setAdapter(adapter);
listView.setOnDataSelectionListener(
new
OnDataSelectionListener () {
public
void
onDataSelected(AdapterView parent, View v,
int
position,
long
id) {
IconTextItem selectItem = (IconTextItem)adapter.getItem(position);
Bundle bundle =
new
Bundle();
bundle.putString(
"data0"
, selectItem.getData(
0
));
bundle.putString(
"data1"
, selectItem.getData(
1
));
Intent intent =
new
Intent( getApplicationContext(), DetailActivity.
class
);
intent.putExtras(bundle);
startActivity ( intent );
}
});
}
protected
void
onDestroy() {
super
.onDestroy();
DatabaseHelper.closeDatabase();
}
public
void
AddCursorData ( Cursor outCursor ) {
int
recordCount = outCursor.getCount();
println(
"cursor count : "
+ recordCount +
"\n"
);
adapter.clear();
int
clasFromCol = outCursor.getColumnIndex(
"CLASFROM"
);
int
clasSoutCol = outCursor.getColumnIndex(
"CLASSOUT"
);
Resources res = getResources();
for
(
int
i =
0
; i < recordCount; i++) {
outCursor.moveToNext();
String clasFrom = outCursor.getString(clasFromCol);
String clasSout = outCursor.getString(clasSoutCol);
adapter.addItem(
new
IconTextItem(res.getDrawable(R.drawable.capsule1),clasSout,clasFrom));
}
outCursor.close();
}
public
void
println(String msg) {
Log.d(TAG, msg);
}