public
class
MainActivity
extends
Activity
implements
TextWatcher,
OnItemClickListener
{
private
static
final
int
LIST_PIC_SCREEN =
0
;
private
static
final
int
VIEW_PIC_SCREEN =
1
;
private
String[] listPicName = {
"androidgirl_1"
,
"androidgirl_2"
,
"androidgirl_3"
,
"beautifulgirl_1"
,
"beautifulgirl_2"
,
"bikinigirl_1"
,
"bikinigirl_2"
,
"bikinigirl_3"
,
"cutegirl_1"
,
"cutegirl_2"
,
"cutegirl_3"
,
"cutegirl_4"
,
"cutegirl_5"
,
"hotgirl_1"
,
"hotgirl_2"
,
"hotgirl_3"
,
"nudegirl_1"
,
"nudegirl_2"
,
"nudegirl_3"
,
"nudegirl_4"
,
"sexygirl_1"
,
"sexygirl_2"
,
"sexygirl_3"
,
"sportgirl_1"
,
"sportgirl_2"
,
"sportgirl_3"
,
"sportgirl_4"
};
private
String[] listPicType = {
"android"
,
"android"
,
"android"
,
"beautiful"
,
"beautiful"
,
"bikini"
,
"bikini"
,
"bikini"
,
"cutegirl"
,
"cutegirl"
,
"cutegirl"
,
"cutegirl"
,
"cutegirl"
,
"hotgirl"
,
"hotgirl"
,
"hotgirl"
,
"nude"
,
"nude"
,
"nude"
,
"nude"
,
"sexy"
,
"sexy"
,
"sexy"
,
"sport"
,
"sport"
,
"sport"
,
"sport"
};
private
int
[]
listPicDrawable = { R.drawable.androidgirl_1,
R.drawable.androidgirl_2,
R.drawable.androidgirl_3,
R.drawable.beautifulgirl_1,
R.drawable.beautifulgirl_2,
R.drawable.bikinigirl_1,
R.drawable.bikinigirl_2,
R.drawable.bikinigirl_3,
R.drawable.cutegirl_1,
R.drawable.cutegirl_2,
R.drawable.cutegirl_3,
R.drawable.cutegirl_4,
R.drawable.cutegirl_5, R.drawable.hotgirl_1,
R.drawable.hotgirl_2,
R.drawable.hotgirl_3, R.drawable.nudegirl_1,
R.drawable.nudegirl_2,
R.drawable.nudegirl_3,
R.drawable.nudegirl_4,
R.drawable.sexygirl_1,
R.drawable.sexygirl_2,
R.drawable.sexygirl_3,
R.drawable.sportgirl_1,
R.drawable.sportgirl_2,
R.drawable.sportgirl_3,
R.drawable.sportgirl_4
};
private
ArrayList<Picture> listPic =
new
ArrayList<Picture>();
private
ListView listview;
private
PicListAdapter adapter;
private
EditText searchEdt;
private
ViewFlipper fliper;
private
ImageView viewpic;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fliper
= (ViewFlipper) findViewById(R.id.viewFlipper1);
listview
= (ListView) findViewById(R.id.listView1);
for
(
int
i =
0
;
i < listPicName.length; i++) {
Picture
pic =
new
Picture(listPicName[i], listPicType[i],
listPicDrawable[i]);
listPic.add(pic);
}
adapter
=
new
PicListAdapter(
this
,
listPic);
listview.setAdapter(adapter);
listview.setOnItemClickListener(
this
);
searchEdt
= (EditText) findViewById(R.id.search_edt);
searchEdt.addTextChangedListener(
this
);
viewpic
= (ImageView) findViewById(R.id.viewpic_img);
}
@Override
public
boolean
onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main,
menu);
return
true
;
}
/**
*
@author 9Android.net
*/
public
void
beforeTextChanged(CharSequence s,
int
start,
int
count,
int
after) {
}
public
void
onTextChanged(CharSequence s,
int
start,
int
before,
int
count) {
}
public
void
afterTextChanged(Editable s) {
String
text = searchEdt.getText().toString().toLowerCase();
adapter.filter(text);
}
/**
*
@author 9Android.net
*/
public
void
onItemClick(AdapterView<?> parent, View view,
int
position,
long
id) {
Sliding.slideFromRightToLeft(VIEW_PIC_SCREEN,
fliper);
viewpic.setImageResource(listPic.get(position).getPicSource());
}
/**
*
@author 9Android.net
*
@param : event, keycode of downed button
*
@Objective : Handle keyevent on main activity
*/
public
boolean
onKeyDown(
int
keyCode, KeyEvent event) {
if
(keyCode == KeyEvent.KEYCODE_BACK) {
int
screen = fliper.getDisplayedChild();
if
(screen == VIEW_PIC_SCREEN) {
Sliding.slideFromLeftToRight(LIST_PIC_SCREEN,
fliper);
return
true
;
}
}
return
super
.onKeyDown(keyCode,
event);
}
}
2 '12 at 11:31
implements the android.widget.Filterable interface which requires getFilter(). – Dustin May
3 '12 at 14:56
tutorial helped me. The answer had some unclear things, or maybe I didn't read it with enough concentration. – Sufian Mar
26 at 10:53