Right now i'm developing a custom combobox. The GUI just like the image below

If i clicked at the New Game (pic-1), the lower part of the ComboBox will appear with a downAnimation (pic-2). If i select an item from the ComboBox, the lower part will disapear with an upAnimation (pic-2) and the selected item will appear just like the pic-1.
But i got a problem :

I want the lower part of the CB to disapear like pic-1 when I don't want to select any items from the ComboBox, so i just clicked anywhere outside the ComboBox in the yellow region (pic-3). Right now it's not possible to do it with my implementation of custom ComboBox. What method should i implement or override in order to do that? onFocusChanged? onFocusChangeListener?

also, how to remove the yellow rectangle in pic-4 (appear when i browse the items in ComboBox). It just don't look good with a blue background with a yellow thing when i select the item
Here is my code :
Using java Syntax Highlighting
- public class MyComboBox extends AbsoluteLayout {
- private MyImageView img;
- private ImageView img2;
- private ListView list;
- private Context ctx;
- private TextView text;
- private String[] content;
- public MyComboBox(Context context,AttributeSet attr, Map inflateParams)
- {
- super(context,attr,inflateParams);
- ctx = context;
- //new AbsoluteLayout.LayoutParams(width,height,x,y));
- img = new MyImageView(ctx);
- img.setImageResource(R.drawable.up_3);
- img.setLayoutParams(new AbsoluteLayout.LayoutParams(209,39,0,0));
- img2 = new ImageView(ctx);
- img2.setImageResource(R.drawable.down_3);
- img2.setLayoutParams(new AbsoluteLayout.LayoutParams(196,166,10,33));
- list = new ListView(ctx);
- list.setLayoutParams(new AbsoluteLayout.LayoutParams(130,168,35,33));
- list.setOnItemClickListener(mItemClickListener);
- text = new TextView(ctx);
- text.setLayoutParams(new AbsoluteLayout.LayoutParams(200,168,70,6));
- img2.setVisibility(INVISIBLE);
- list.setVisibility(INVISIBLE);
- super.addView(img);
- super.addView(img2);
- super.addView(list);
- super.addView(text);
- }
- private OnItemClickListener mItemClickListener = new OnItemClickListener()
- {
- @Override
- public void onItemClick(AdapterView parent, View v, int position, long id) {
- text.setText((String)parent.getAdapter().getItem(position));
- upAnimation();
- img2.setVisibility(INVISIBLE);
- list.setVisibility(INVISIBLE);
- }
- };
- public void setContent(String[] str)
- {
- content = str;
- list.setAdapter(new MyListAdapter(ctx));
- }
- private void upAnimation()
- {
- Animation up = AnimationUtils.loadAnimation(ctx, R.anim.push_up_out);
- img2.startAnimation(up);
- list.startAnimation(up);
- }
- private void downAnimation()
- {
- Animation down = AnimationUtils.loadAnimation(ctx, R.anim.push_down_out);
- img2.startAnimation(down);
- list.startAnimation(down);
- }
- private class MyImageView extends ImageView {
- }
- private class MyListAdapter extends BaseAdapter {
- }
- private class MyView extends LinearLayout {
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
the MyImageView class :
Using java Syntax Highlighting
- private class MyImageView extends ImageView {
- public MyImageView(Context context) {
- super(context);
- }
- @Override
- public boolean onMotionEvent(MotionEvent event) {
- int action = event.getAction();
- boolean mCurDown = action == MotionEvent.ACTION_DOWN;
- if (mCurDown) {
- if (img2.getVisibility() == VISIBLE) {
- img2.setVisibility(INVISIBLE);
- list.setVisibility(INVISIBLE);
- upAnimation();
- } else {
- img2.setVisibility(VISIBLE);
- list.setVisibility(VISIBLE);
- downAnimation();
- list.requestFocus();
- }
- }
- return true;
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
the MyListAdapter class :
Using java Syntax Highlighting
- private class MyListAdapter extends BaseAdapter {
- public MyListAdapter(Context context) {
- mContext = context;
- }
- public int getCount() {
- return content.length;
- }
- public Object getItem(int position) {
- return content[position];
- }
- public long getItemId(int position) {
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- MyView sv;
- if (convertView == null) {
- sv = new MyView(mContext, content[position]);
- } else {
- sv = (MyView) convertView;
- sv.setText(content[position]);
- }
- return sv;
- }
- private Context mContext;
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
and the MyView class :
Using java Syntax Highlighting
- private class MyView extends LinearLayout {
- private TextView text;
- public MyView(Context context, String str) {
- super(context);
- this.setOrientation(VERTICAL);
- text = new TextView(context);
- text.setHeight(20);
- text.setAlignment(Alignment.ALIGN_CENTER);
- text.setText(str);
- addView(text, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
- }
- public void setText(String title) {
- text.setText(title);
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Thank you








