best way to implement pop up window in android application - android

I have the main activity in which I have few menu buttons. When the user presses specific button I want to open a new activity which also have a couple of buttons which I need to handle their click. In other words, I need to pop up window functionality as normal activity.
I looked online and found several ways to implement this such as: just customising the size of the activity, use diaglog theme in the manifest, use it as a fragment or use Popup Window Class. But as I am new to android I want the best way to implement it for my project.
Can someone help me achieve this?
EDIT:
this is the xml file i want to use in the pop up window (for better explanation of what i want to achieve):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#0091cb"
android:padding="16dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="#dimen/activity_horizontal_margin"
android:weightSum="3"
android:id="#+id/check">
<Button
android:layout_width="85dp"
android:layout_height="85dp"
android:background="#drawable/circle"
android:drawableTop="#drawable/computer"
android:paddingTop="12dp"
android:layout_marginLeft="10dp"
android:text="button1"
android:textSize="10dp"
android:textColor="#fff"
android:layout_weight="1"
android:onClick="button1_OnClick"/>
<Button
android:layout_width="85dp"
android:layout_height="85dp"
android:background="#drawable/circle"
android:drawableTop="#drawable/electrical"
android:paddingTop="12dp"
android:layout_marginLeft="10dp"
android:text="button2"
android:textSize="10dp"
android:textColor="#fff"
android:layout_weight="1"
android:onClick="button2_OnClick"/>
<Button
android:layout_width="85dp"
android:layout_height="85dp"
android:background="#drawable/circle"
android:drawableTop="#drawable/hdtv"
android:paddingTop="12dp"
android:layout_marginLeft="10dp"
android:text="button3"
android:textSize="10dp"
android:textColor="#fff"
android:layout_weight="1"
android:onClick="button3_OnClick"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:orientation="horizontal"
android:layout_below="#id/check"
android:paddingTop="10dp">
<Button
android:layout_width="85dp"
android:layout_height="85dp"
android:background="#drawable/circle"
android:drawableTop="#drawable/bill"
android:paddingTop="12dp"
android:layout_marginLeft="10dp"
android:text="button4"
android:textSize="10dp"
android:textColor="#fff"
android:onClick="button4_OnClick"/>
<Button
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_marginLeft="10dp"
android:background="#drawable/circle"
android:drawableTop="#drawable/water"
android:paddingTop="12dp"
android:text="button5"
android:textSize="10dp"
android:textColor="#fff"
android:onClick="button5_OnClick" />
<Button
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_marginLeft="10dp"
android:background="#drawable/circle"
android:drawableTop="#drawable/electrical"
android:paddingTop="12dp"
android:text="button6"
android:textSize="10dp"
android:textColor="#fff"
android:onClick="button6_OnClick" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:orientation="horizontal">
<Button
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_marginLeft="10dp"
android:background="#drawable/circle"
android:drawableTop="#drawable/notepad"
android:paddingTop="7dp"
android:text="button7"
android:textSize="10dp"
android:textColor="#fff"
android:onClick="button7_OnClick" />
</LinearLayout>
</LinearLayout>

Depends on your needs.
If you need just to show 'classic' popup window (error while typing in input field or small color picker) - use PopupWindow class. You can use my gist.
If your message is more general (e.g. 'There is no internet connection') or user should choose yes/no - use dialog. There is cool library.
Activity with custom size is used rarely. Maybe in some dial applications.
So choose implementation depends on your needs.

create method where u want to open popup windiw in your activity
Like this,here p is a specific point(location) where you want exactly open your window.
final Point p = new Point();
show_popup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showpopupwindows(Activity, p);
}
});
then,
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
int location[] = new int[2];
show_popup.getLocationOnScreen(location);
p.x = location[0];
p.y = location[1];
}
private void showpopupwindows(final Activity context, Point p) {
LinearLayout viewGroup = (LinearLayout) context
.findViewById(R.id.popup_menu);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Display display = context.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int popupwidth = (size.x / 2);
int popupheight =(size.y / 2);
View layout = layoutInflater.inflate(R.layout.detail_pop, viewGroup);
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupwidth);
popup.setHeight(popupheight);
popup.setFocusable(true);
popup.setAnimationStyle(R.style.WindowAnimation);
popup.setBackgroundDrawable(new ColorDrawable(
android.graphics.Color.TRANSPARENT));
popup.showAtLocation(layout, Gravity.NO_GRAVITY, popupwidth,popupheight);
detail_pop1 = (TextView) layout.findViewById(R.id.detail_pop1);
detail_pop1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getContext(), "pop window is opened, Toast.LENGTH_SHORT).show();
}
});
}
detail_pop.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup_menu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#color/skyblue"
android:gravity="center"
android:orientation="vertical"
>
<TextView
android:id="#+id/detail_pop1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:drawableTop="#drawable/ic_launcher"
android:gravity="center"
android:text="P"
android:textSize="#dimen/font_24" />
</LinearLayout>

Related

How to position an ImageView in the same place in different screen sizes?

I been working on a simple android app that calculates a person's Body Mass Index, I have all the features working but positioning the arrow in the right place in the color bar corresponding to the user's screen size is what Im stuck on. I have it working by setting the X and Y values of the arrow ImageView but obviously the place of the arrow changes when i test my application in different screen sizes even though im coverting a dp value to pixels. How can I position the arrow ImageView so that it stays the same in different screen sizes?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="coding.guillermo.bmiapp.MainActivity2"
tools:showIn="#layout/activity_main2"
android:clickable="false"
android:background="#ffffff"
android:id="#+id/relativeLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BMI"
android:id="#+id/bmiText"
android:textSize="25dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="21.24"
android:id="#+id/bmiResult"
android:textSize="30dp"
android:layout_below="#+id/bmiText"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bmiCategory"
android:textSize="25dp"
android:text="Normal weight"
android:layout_marginTop="22dp"
android:layout_below="#+id/bmiResult"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save result"
android:id="#+id/saveButton"
android:backgroundTint="#color/toolBarColor"
android:textColor="#ffffff"
android:layout_marginBottom="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BMI Log"
android:id="#+id/trackerButton2"
android:backgroundTint="#color/toolBarColor"
android:textColor="#ffffff"
android:layout_alignTop="#+id/saveButton" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:background="#drawable/bmibar"
android:layout_marginTop="36dp"
android:layout_below="#+id/bmiCategory" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Underweight <18.50 "
android:id="#+id/underweightText"
android:textSize="22sp"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal 18.5 - 24.99"
android:id="#+id/normalText"
android:textSize="22sp"
android:paddingTop="5dp"
android:layout_below="#+id/underweightText"
android:layout_alignStart="#+id/underweightText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overweight >=25.00"
android:id="#+id/overweightText"
android:layout_below="#+id/normalText"
android:textSize="22sp"
android:paddingTop="5dp"
android:layout_alignStart="#+id/normalText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Obese >=30.00"
android:id="#+id/obeseText"
android:textSize="22sp"
android:paddingTop="5dp"
android:layout_below="#+id/overweightText"
android:layout_alignStart="#+id/overweightText" />
public class MainActivity2 extends AppCompatActivity {
TextView resultText,bmiLabel,underWeightText,normalText,overweightText,obeseText;
RelativeLayout.LayoutParams params;
Button saveButton,trackerButton;
Result result;
EditText userName;
DBhandler dbHandler;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
// TextViews
resultText = (TextView) findViewById(R.id.bmiResult);
bmiLabel = (TextView) findViewById(R.id.bmiCategory);
underWeightText = (TextView) findViewById(R.id.underweightText);
normalText = (TextView) findViewById(R.id.normalText);
overweightText = (TextView) findViewById(R.id.overweightText);
obeseText = (TextView) findViewById(R.id.obeseText);
// Button
saveButton = (Button) findViewById(R.id.saveButton);
trackerButton = (Button) findViewById(R.id.trackerButton2);
// Getting User object from the previous activity
result = (Result) getIntent().getParcelableExtra("result");
// Database
dbHandler = new DBhandler(this);
// Displaying the arrow in the corresponding place
ImageView arrow = new ImageView(this);
params = new RelativeLayout.LayoutParams(80,80);
arrow.setImageResource(R.drawable.arrow2);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.relativeLayout);
// the display of the arrow is different when tested in device's with different screen sizes
int dpValue = 0;
int dpValue2 = 166;
float d = getApplicationContext().getResources().getDisplayMetrics().density;
int margin = (int)(dpValue * d);
int margin2 = (int) (dpValue2 * d);
arrow.setX(margin);
arrow.setY(margin2);
rl.addView(arrow);
// BMI diplay
resultText.setText(Double.toString(result.getBMI()));
bmiLabel.setText(result.getBmiCategory());
// BMI category bold display
bmiCategoryBold(result.getBMI());
// Saving result to internal storage for later retrieval
saveButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View view = (LayoutInflater.from(MainActivity2.this)).inflate(R.layout.alert_content,null);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity2.this);
alertBuilder.setView(view);
userName = (EditText) view.findViewById(R.id.nameInput);
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
String date = dateFormat.format(new Date());
result.setDate(date);
alertBuilder.setCancelable(true).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
result.setName(userName.getText().toString());
// adding result to the SQLite database
dbHandler.addResult(result);
Toast toast = Toast.makeText(getApplicationContext(),"result saved",Toast.LENGTH_SHORT);
toast.show();
}
});
AlertDialog dialog = alertBuilder.create();
dialog.show();
Button nButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
nButton.setBackgroundColor(getResources().getColor(R.color.toolBarColor));
nButton.setTextColor(Color.WHITE);
}
});
trackerButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),MainActivity3.class);
startActivity(intent);
}
});
}
public void bmiCategoryBold(double bmi){
if(bmi < 18.50){
underWeightText.setTypeface(null, Typeface.BOLD);
}
else if(bmi <= 24.99){
normalText.setTypeface(null,Typeface.BOLD);
}
else if(bmi<=29.99){
overweightText.setTypeface(null,Typeface.BOLD);
}
else{
obeseText.setTypeface(null,Typeface.BOLD);
}
}
}
The first pic is the app running on 1080 pixels by 1920 pixels screen and the second is a 1440 pixels by 2560 pixels screen
first pic
second pic
Add Linearlayout as subparent of childview,use its orientation and gravity attribute you can easily get the design in more optimize way and suitable for everyscreen size.
here i have used RelativeLayout as Parent and LinearLayout as sub-parent of childview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/bmiText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BMI"
android:textSize="25dp" />
<TextView
android:id="#+id/bmiResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="21.24"
android:textSize="30dp" />
<TextView
android:id="#+id/bmiCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal weight"
android:textSize="25dp" />
</LinearLayout>
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="#+id/underweightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Underweight <18.50 "
android:textSize="22sp" />
<TextView
android:id="#+id/normalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Normal 18.5 - 24.99"
android:textSize="22sp" />
<TextView
android:id="#+id/overweightText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Overweight >=25.00"
android:textSize="22sp" />
<TextView
android:id="#+id/obeseText"
android:layout_width="wrap_content"
android:padding="10dp"
android:layout_height="wrap_content"
android:text="Obese >=30.00"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:gravity="left"
android:layout_height="wrap_content">
<Button
android:id="#+id/trackerButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#000000"
android:text="BMI Log"
android:gravity="center"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content">
<Button
android:id="#+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:backgroundTint="#000000"
android:text="Save result"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Try to avoid too much margin top and bottom.

How to create buttons like keyboard keys in android?

This question seems trivial. I want to create a button like keyboard keys for my app. When I click on it, a popup window appears above that button showing the letter pressed. Everything works great till now except one thing. When I add onFocusChangedListener to the button, nothing happens. I need to let my button act as a keyboard key, but I don't know how.
As you can see here, when a button is focused, a popup window appears. I want to do that, but onFocusChangeListener doesn't work. I know I can use a KeyboardView to achieve that, but I don't want to use that due to some other issues like centering buttons and setting keys' height with layout_weight. So I need to make it with normal buttons.
What I tried:
My First Try:
button.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
popupWindow.showAtLocation(keyboardPopup, Gravity.NO_GRAVITY, location.left - 10, location.top - button.getHeight());
} else {
popupWindow.dismiss();
}
}
});
Result: Nothing happened. The popup window didn't appear at all.
Edit: After I have added button.setFocusableInTouchMode(true); as Ashley suggested, onFocusChanged is now getting called, but it acts so weird. The popup is sometimes shown, but at the same time when it is shown, it never disappears...
My Second Try:
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
popupWindow.showAtLocation(keyboardPopup, Gravity.NO_GRAVITY, location.left - 10, location.top - button.getHeight());
break;
case MotionEvent.ACTION_UP:
popupWindow.dismiss();
break;
}
return true;
}
});
Result: This one acted so weird. Sometimes the popup shows and sometimes not, but when it is shown, the button didn't also change its state. It should have been focused, but nothing happened to the button, it acts as if it was in a normal state (Button's background doesn't change with state_focused declared in my drawable xml). It seems that onTouchListener overrides the button's functionality.
Here is a part of my layout:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Q"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="W"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="E"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="R"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="T"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Y"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="U"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="I"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="O"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="P"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<View
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="A"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="S"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="D"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="F"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="G"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="H"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="J"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="K"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="L"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<View
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<View
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1.5" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Z"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="X"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="C"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="V"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="B"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="N"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="M"
android:background="#drawable/keyboard_button"
android:textColor="#FFFFFF"
android:onClick="onKeyboardClick" />
<View
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1.5" />
</LinearLayout>
</LinearLayout>
In code:
public void onKeyboardClick(View view) {
//The view pressed is a button.
final Button button = (Button) view;
//Create a PopupWindow.
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
final View keyboardPopup = inflater.inflate(R.layout.keyboard_popup, null);
final PopupWindow popupWindow = new PopupWindow(keyboardPopup, view.getWidth() + 20, view.getHeight());
TextView keyboardKey = (TextView) keyboardPopup.findViewById(R.id.keyboard_key);
keyboardKey.setText(button.getText().toString());
//Get button location to show the popup above it.
int[] keyLocation = new int[2];
button.getLocationOnScreen(keyLocation);
final Rect location = new Rect();
location.left = keyLocation[0];
location.top = keyLocation[1];
location.right = location.left + button.getWidth();
location.bottom = location.top + button.getHeight();
//This is a temporary solution. I don't want to use that.
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Show popup.
popupWindow.showAtLocation(keyboardPopup, Gravity.NO_GRAVITY, location.left - 10, location.top - button.getHeight());
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//Dismiss popup.
popupWindow.dismiss();
}
}, 200);
}
});
}
Any help will be greatly appreciated. Thanks.
I suggest you use the second try onTouchListener!
You had 2 issues with that:
1. The button does not change state
Indeed, when you override the onTouchListener you must simulate the state yourself. Please take a look at this SO thread for how it is done:
"Press and hold" button on Android needs to change states (custom XML selector) using onTouchListener
2. Sometime shows and sometimes not
This should not happen, especially if you handle all the relevant touch event cases properly. You will want to show the pop up when the user touch down on a button and hide that pop up when a user move out of the button (either by swiping out or taking the finger off the screen).
Please try the following code sample:
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
v.setPressed(true);
showPopupWindow(...);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_CANCEL:
v.setPressed(false);
hidePopupWindow(...);
break;
}
return true;
}
});
Notice the use of getActionMasked instead of getAction to better handle multi touch.
Notice the v.setPressed(...); - this will update the button state.
Notice the different cases of hiding the pop up.
Instead of setting an OnTouchListener, try subclassing Button and overriding onTouchEvent itself:
public class KeyboardButton extends Button
{
#Override
public boolean onTouchEvent(MotionEvent event)
{
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
popupWindow.showAtLocation(keyboardPopup, Gravity.NO_GRAVITY, location.left - 10, location.top - button.getHeight());
break;
case MotionEvent.ACTION_UP:
popupWindow.dismiss();
break;
}
return super.onTouchEvent(event);
}
}
I didn't notice it in your code but potentially you left out.
btn.setFocusableInTouchMode(true);
btn.setFocusable(true);
For the on focus change listener.
holder.sAttedenceList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
if (!parent.hasFocus()) {
return;
}
not the full code but this the general structure that worked for me.

Android - Buttons to appear as if absolute, ignore scrolling content?

I have a listview populated by an adapter which, as expected, is scrollable when the content exceeds the boundaries of the page.
I also have two buttons below the list. What I want to do is have these two buttons appear at the bottom of the page right away, and remain there even if the content is scrolled, exactly like the "position: absolute" property for a website would work.
Here is the code I have... I've tried several methods but unfortunately our client wants as many pages to be created dynamically as possible, so I can't use any XML to do this, only the java class.... Hopefully one of you genius' people can help!
/**
* MaterialsActivity
*
* Activity to display list of materials used for a fault.
*/
public class MaterialsActivity extends ListActivity implements DialogCloseListener {
private String faultId = null;
private ProgressDialog progressDialog;
private MaterialListAdapter adapter = null;
/* (non-Javadoc)
* #see android.app.Activity#onCreate(android.os.Bundle)
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get data passed in (faultId)
Bundle extras = getIntent().getExtras();
if (extras != null) {
faultId = extras.getString("faultId");
}
// Check device id valid
if (faultId == null || faultId.length() == 0) {
ErrorDialog ed = new ErrorDialog(this, "No fault specified");
ed.show();
setResult(RESULT_CANCELED);
finish();
}
// Set up add button and handler
Button btnAdd = new Button(this);
btnAdd.setText("Add New Material Entry");
btnAdd.set
btnAdd.setOnClickListener(new Button.OnClickListener() {
//On click open add activity, passing next id to use
//(ID system used not very robust but sticking with way existing FMS does things)
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(MaterialsActivity.this, MaterialsAddActivity.class.getName());
intent.putExtra("faultId", faultId);
if (adapter != null) {
intent.putExtra("newMaterialUsedId", adapter.getNextId());
}
startActivityForResult(intent, 0);
}
});
this.getListView().addFooterView(btnAdd);
// Set up remove button and handler
Button btnRemove = new Button(this);
btnRemove.setText("Remove Material Entry");
btnRemove.setOnClickListener(new Button.OnClickListener() {
//On click open add activity, passing next id to use
//(ID system used not very robust but sticking with way existing FMS does things)
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName(MaterialsActivity.this, MaterialsRemoveActivity.class.getName());
intent.putExtra("faultId", faultId);
if (adapter != null) {
intent.putExtra("newMaterialUsedId", adapter.getNextId());
}
startActivityForResult(intent, 1);
}
});
// Add the button to the footer (needs to be done after setting it up)
this.getListView().addFooterView(btnRemove);
// Set list adapter
adapter = new MaterialListAdapter(MaterialsActivity.this, R.layout.materials_list_item2, new ArrayList<MaterialsUsed>());
setListAdapter(adapter);
//Start new asynctask to retrieve materials list and show wait indicator
new LoadMaterialsUsed().execute(faultId);
progressDialog = ProgressDialog.show(MaterialsActivity.this, "", "Loading. Please wait...", true);
}
The ListAdapter populates the following XML with each row from my DB table, so it runs X amount of times until it has retrieved each row.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
>
<TextView
android:id="#+id/materialTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingTop="20dp"
android:text="Material : "
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/matMaterial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/materialTitle"
android:gravity="right"
android:paddingTop="20dp"
android:paddingRight="15dp"
android:textColor="#acacac"
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/assetNoTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/materialTitle"
android:gravity="left"
android:text="Asset No : "
android:paddingTop="5dp"
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/matAssetNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/assetNoTitle"
android:layout_below="#id/matMaterial"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:textColor="#acacac"
android:textSize="15sp" >
</TextView>
<!-- <TextView
android:id="#+id/equipmentTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/assetNoTitle"
android:gravity="left"
android:text="Equipment : "
android:textSize="15sp"
android:paddingTop="5dp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/matEquipment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/equipmentTitle"
android:layout_below="#id/matAssetNo"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:textColor="#acacac"
android:textSize="15sp" >
</TextView> -->
<TextView
android:id="#+id/manufacturerTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/assetNoTitle"
android:gravity="left"
android:text="Manufacturer : "
android:textSize="15sp"
android:paddingTop="5dp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/matManufacturer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/manufacturerTitle"
android:layout_below="#id/matAssetNo"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:textColor="#acacac"
android:textSize="15sp" >
</TextView>
<TextView
android:id="#+id/modelTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/manufacturerTitle"
android:gravity="left"
android:text="Model : "
android:textSize="15sp"
android:paddingTop="5dp"
android:textStyle="bold">
</TextView>
<TextView
android:id="#+id/matModel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/matManufacturer"
android:layout_toRightOf="#id/modelTitle"
android:gravity="right"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:textColor="#acacac"
android:textSize="15sp" >
</TextView>
<!-- <TextView
android:id="#+id/descriptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/modelTitle"
android:gravity="left"
android:text="Description : "
android:textSize="15sp"
android:paddingTop="5dp"
android:textStyle="bold">
</TextView>
<TextView
android:id="#+id/matDescription"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_alignParentRight="true"
android:layout_below="#id/matModel"
android:layout_toRightOf="#id/descriptionTitle"
android:textColor="#acacac"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:textSize="15sp" >
</TextView> -->
<TextView
android:id="#+id/serialNoTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/modelTitle"
android:gravity="left"
android:text="Serial No : "
android:textSize="15sp"
android:paddingTop="5dp"
android:paddingBottom="20dp"
android:textStyle="bold">
</TextView>
<TextView
android:id="#+id/matSerialNo"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/serialNoTitle"
android:layout_below="#id/matModel"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="20dp"
android:textColor="#acacac"
android:textSize="15sp">
</TextView>
<!-- <TextView
android:id="#+id/modifiedByTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/serialNoTitle"
android:gravity="left"
android:text="Modified By : "
android:textSize="15sp"
android:paddingTop="5dp"
android:textStyle="bold">
</TextView>
<TextView
android:id="#+id/matModifiedBy"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/modifiedByTitle"
android:layout_below="#id/matSerialNo"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:textColor="#acacac"
android:textSize="15sp" >
</TextView>
<TextView
android:id="#+id/modifiedTimeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/modifiedByTitle"
android:gravity="left"
android:text="Modified Time : "
android:textSize="15sp"
android:paddingTop="5dp"
android:paddingBottom="20dp"
android:textStyle="bold">
</TextView>
<TextView
android:id="#+id/matModifiedTime"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/modifiedTimeTitle"
android:layout_below="#id/matModifiedBy"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="20dp"
android:textColor="#acacac"
android:textSize="15sp" >
</TextView> -->
<View
android:background="#drawable/white"
android:layout_height="2dp"
android:layout_width="fill_parent"/>
</RelativeLayout>
If you could change the XML where ListView resides in, it would be dead easy.
Since you can't, you'll need to use a few hacks. Here's a step by step plan:
Add the button to the ListView's parent layout.
Measure the button's height
Then wait for the ListView to be drawn so you can measure it's height.
Finally set the ListView's height so the button is visible (not overlayed by the list)
Here's a sample I've tried:
ViewGroup viewGroup = (ViewGroup) listView.getParent();
Button button = new Button(this);
button.setText("Button");
button.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
viewGroup.addView(button);
// Button height
button.measure(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
final int buttonHeight = button.getHeight();
Log.e("TAG", "Button height: " + buttonHeight);
// ListView height
listView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
#Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
listView.removeOnLayoutChangeListener(this);
int listHeight = listView.getMeasuredHeight();
Log.e("TAG", "List height: " + listHeight);
// ListView's height = listHeight - buttonHeight
listView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, listHeight - buttonHeight));
}
});
Notes:
This sample assumes that the ListView's parent is a LinearLayout.
It will add the button after every other in the parent layout.
If, however, the parent is a RelativeLayout, you'll have to play around with layoutParams.addRule(RelativeLayout.BOTTOM_OF, listView.getId());
I guess your xml looks somthing like this
<LinearLayout android:orientation="vertical">
<ListView>
...
</ListView>
<LinearLayout android:orientation="horizontal">
<Button />
<Button />
</LinearLayout>
</LinearLayout>
I would not use a ListView but a LinearLayout inside of a ScrollView and dynamically add TextView item to the Layout
<LinearLayout android:orientation="vertical">
<ScrollView>
<LinearLayout android:orientation="vertical">
<TextView />
<TextView />
...
</LinearLayout>
</ScrollView>
<LinearLayout android:orientation="horizontal">
<Button />
<Button />
</LinearLayout>
</LinearLayout>
you just need to add all missing attributes like weights, width,height etc
edit:
The idea is the same if would generate all views with java code instead of an XML defenition
in your xml you have to do something like this...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" >
<ListView
android:layout_above="#+id/ll_buttons">
</ListView>
<LinearLayout
android:id="#+id/ll_buttons"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
</LinearLayout>
</RelativeLayout>
this will set your buttons on bottom of screen always and the list view will always be above the LinearLayout containing the list items(i.e ofcourse scrollable).
For Dynamic buttons.. add in layout
Button button = new Button(this) ///this is a context object
button.setWidth(100);
button.setText("Save");
layout.addView(button);

popup layout not centered in Gingerbread device

I have a problem with a custom layout.
When running it on emulators, the popup adjusts itself to the size of my custom layout, yet when I run it on my Atrix, this happens:
As you can see, the layout is not centered.
Now, this is my custom layout:
<TextView
android:id="#+id/txtVersus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:padding="10dp"
android:text="#string/popup_unlock"
android:textColor="#FFFFFFFF"
android:textSize="20sp"
android:visibility="visible" />
<ImageView
android:id="#+id/imgPopup"
android:layout_width="#dimen/imagen_config_width"
android:layout_height="#dimen/imagen_config_height"
android:layout_gravity="center"
android:background="#drawable/char_cersei"/>
<net.rahl.rahlutils.CustomFontTextView
android:id="#+id/txtPopupName"
style="#style/ConfigText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="3dp"/>
<net.rahl.rahlutils.CustomFontTextView
android:id="#+id/txtPopupCasa"
style="#style/ConfigText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="3dp"/>
<Button
android:id="#+id/btnCerrarPopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="#string/ok" />
And this is my part of the code where I set and show it:
final Dialog dialog = new Dialog(con);
dialog.setTitle("Felicidades!");
dialog.setContentView(R.layout.unlockdialog);
((ImageView) dialog.findViewById(R.id.imgPopup)).setBackgroundResource(con.getResources().getIdentifier("char_" + name.toLowerCase(), "drawable", con.getPackageName()));
((TextView) dialog.findViewById(R.id.txtPopupName)).setText(name);
((TextView) dialog.findViewById(R.id.txtPopupCasa)).setText(casa);
((Button) dialog.findViewById(R.id.btnCerrarPopup)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
dialog.cancel();
}
});
dialog.setCanceledOnTouchOutside(false);
dialog.show();
Do you know how to fix this?

Android: Change Spinner Dropdown view

Im My application I want the below type of Spinner Dropdown view .
For this type of spinner view. I wrote this code.
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.spinner, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_obj.setAdapter(adapter);
I got this from http://developer.android.com/guide/topics/ui/controls/spinner.html
But what I got is,
Please provide me the best way to do this....
Kind of reviving an old post here but the accepted answer is far from ideal. The correct way to do this is to set the Spinner to dropdown mode in your layout xml:
<Spinner
android:id="#+id/my_spinner"
...
android:spinnerMode="dropdown"/>
The available options are "dialog" and "dropdown".
Your application is running on old theme.
If you are using android 4.2 set android application theme (in the manifest file) to
android:theme="#android:style/Theme.Holo.Light"
OR
android:theme="#android:style/Theme.Holo.Light.DarkActionBar"
may be you are running in below than 4.0 , 4.0 will show you dropdown as your image
You can use popup like below:
spinner=(EditText)findViewById(R.id.txt_Spinner);
spinner.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
p = new Point();
p.x = location[0]+(v.getHeight());
p.y = location[1]+v.getHeight();
if (p != null)
showPopup(statusActivity.this, p);
System.out.println("show popup");
}
});
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
int popupWidth = 300;
int popupHeight = 500;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
// Creating the PopupWindow
popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
int OFFSET_X = 00;
int OFFSET_Y = 00;
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
((TextView)layout.findViewById(R.id.textView2)).setClickable(true);
((TextView)layout.findViewById(R.id.textView3)).setClickable(true);
((TextView)layout.findViewById(R.id.textView4)).setClickable(true);
((TextView)layout.findViewById(R.id.textView5)).setClickable(true);
((TextView)layout.findViewById(R.id.textView6)).setClickable(true);
((TextView)layout.findViewById(R.id.textView7)).setClickable(true);
((TextView)layout.findViewById(R.id.textView8)).setClickable(true);
((TextView)layout.findViewById(R.id.textView9)).setClickable(true);
}
and popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/popup_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_orange_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Status"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="Sleeping"
android:text="Sleeping" />
<TextView
android:id="#+id/textView3"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="Available"
android:text="Available" />
<TextView
android:id="#+id/textView4"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="Busy"
android:text="Busy" />
<TextView
android:id="#+id/textView5"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="At work"
android:text="At work" />
<TextView
android:id="#+id/textView6"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="Battery charge low"
android:text="Battery charge low" />
<TextView
android:id="#+id/textView7"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="In meeting"
android:text="In meeting" />
<TextView
android:id="#+id/textView8"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="TMS me later"
android:text="TMS me later" />
<TextView
android:id="#+id/textView9"
style="#style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="#drawable/line_white"
android:tag="At the toilet"
android:text="At the toilet" />
<EditText
android:id="#+id/textCustomize"
style="#style/text_blue_contains"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:tag="Customize"
android:text="Customize" />
</LinearLayout>
For the GUI Use HoloEverywhere. https://github.com/Prototik/HoloEverywhere
HoloEverywhere is the best way to go if you want Holo theme on older Android then 4.0 .
And for the dropdown use android:spinnerMode="dropdown" in the layout as Stephen Kidson mentioned.
Its a AutocompleteTextView widget that you are suppose to use but you have tried with Spinner widget.
If my guess is right, Please refer the link.
AutocompleteTextView
Cheers.

Categories

Resources