I am trying to build a simple Android app one of whose activities will have a Google Places AutoCompleteTextView along with a Button and several other components. However, it seems to be the case that the AutoCompleteTextView component does not want to play friendly with anything else. Currently, I can only get one (the AutoCompleteTextView component) or the others rendering at a time. Here are the relevant portions of my code:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Please enter your place" >
<requestFocus />
</AutoCompleteTextView>
<Button
android:id="#+id/btnChangeDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Date" />
<TextView
android:id="#+id/lblDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Date (M-D-YYYY): "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<DatePicker
android:id="#+id/dpResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
list_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
GooglePlacesAutocompleteActivity.java
public class GooglePlacesAutocompleteActivity extends Activity implements OnItemClickListener {
// class fields are here ...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setCurrentDateOnView(); // sets up the date picker
addListenerOnButton(); // adds a listener to a Button
// next three lines configure the Google Place autocomplete
AutoCompleteTextView autoCompView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
autoCompView.setAdapter(new GooglePlacesAutocompleteAdapter(this, R.layout.list_item));
autoCompView.setOnItemClickListener(this);
}
// more methods...
}
If you need more information to render an answer here, please feel free to ask me and I will post as soon as I can.
Hi You have a problem of orientation in your LinearLayout. I guess you want your AutocompleteTextView in top of the rest. If that is the case you should probably add a nested LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Please enter your place" >
<requestFocus />
</AutoCompleteTextView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
[your other items]
</LinearLayout>
</LinearLayout>
If this is not what you are looking for just change match_parent to wrap_content for thw width of your AutocompleteTextView.
Related
I know the code might not be well formatted but I want the button (last tag) to always appear in front
of all other views if the description is long the button disappears.
I'm using scrollView and if any long text appears but this makes the button go down the screen.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical">
<Button
android:layout_gravity="bottom|end"
android:id="#+id/cart_button"
android:layout_width="250dp"
android:layout_height="55dp"
android:layout_marginBottom="10dp"
android:iconTint="#color/black"
android:elevation="6dp"
android:text="ADD TO CART"
android:textAppearance="?attr/textAppearanceButton"
android:textColor="#28022E"
android:textSize="20sp"
app:backgroundTint="#F6F2FA"
app:elevation="10dp"
app:rippleColor="#FFF"
app:shapeAppearance="?attr/shapeAppearanceSmallComponent"
app:strokeColor="#0000"
app:strokeWidth="10dp" />
</RelativeLayout>
Take your button out of scrollview.
something like :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
// content that you wants to scroll
</ScrollView>
<Button alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
I have a TextView on top of ProgressBar. When ProgressBar changes then the position of the TextView have to change on top of progression. How can I create such a solution?
Output :
Try using progressBar getProgress method and then change the text with setText method!
int state = progressBar.getProgress();
textView.setText(state);
Follow this
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
android:background="#d6e6de"
>
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create ProgressBar"
/>
<Button
android:id="#+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Operation"
android:layout_toRightOf="#id/btn"
/>
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/btn_start"
/>
</RelativeLayout>
Refer this below examples..
https://android--code.blogspot.in/2015/08/android-create-progressbar.html
and
How to animate the textview (very very long text )scroll automatically horizontally
This question already has answers here:
Multi-line EditText with Done action button
(17 answers)
Closed 5 years ago.
I have a simple contact form on my Android app, it has a Name and Message field and a submit button.
The form works fine, my issue is with the layout/behaviour of the keyboard.
When the user clicks on the Name field, the keyboard pops up and they enter their name and the keyboard then displays 'Next' button, so they can move to the Message field, but then the keyboard changes to 'Enter' for a carriage return, because the android:inputType is textMultiLine
The issue is that now the 'Submit' button is hidden behind the keyboard and the user has to hit the 'back' button to then see the submit button to submit the form.
If I change the android:inputType from textMultiLine to text, the keyboard displays 'Done' which works well, but now all the text entered in the Message field is all on one line and this isn't ideal either.
The ideal solution would be for the keyboard to display the 'Next' so that I can jump to the 'Submit' button (which I do not think is possible) or for the screen to scroll up to see the 'Submit' button (or at least be scrollable).
Any ideas on how I can do this? Thank you.
Thank you.
Here is my activity_contact.xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context="com.mycompany.myapp.fragments.HomeFragment">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/bgplain"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/toplinear">
<LinearLayout
android:id="#+id/linearmenu"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/menu"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/menu"/>
</LinearLayout>
<LinearLayout
android:layout_below="#+id/linearmenu"
android:layout_width="match_parent"
android:layout_above="#+id/tvvolume"
android:layout_height="130dp"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/lineartitle"
android:layout_below="#+id/linearmenu"
android:layout_width="match_parent"
android:layout_weight="4"
android:layout_height="120dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/logo"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_below="#+id/toplinear"
android:layout_width="match_parent"
android:paddingBottom="20dp"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingTop="10dp"
android:paddingRight="15dp"
android:layout_height="match_parent">
<TextView
android:text="Name"
android:textColor="#000000"
android:textSize="16sp"
android:textAllCaps="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/edtname"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="16sp"
android:singleLine="true"
android:inputType="textPersonName"
android:paddingLeft="10dp"
android:hint="Enter name here"
android:background="#drawable/edtback"/>
<TextView
android:text="Message"
android:textAllCaps="true"
android:textColor="#000000"
android:textSize="16sp"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/edtmessage"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="top"
android:inputType="textMultiLine"
android:padding="10dp"
android:textSize="16sp"
android:hint="Enter message here"
android:background="#drawable/edtback"/>
<Button
android:id="#+id/btnsubmit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Submit"
android:textAllCaps="true"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:background="#drawable/btnback"
android:layout_marginTop="20dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
Update : I've tried adding a android:imeOptions="actionNext" to the Message field, but it won't override it, presumably because it is a textMultiLine type field(?)
How about adding
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
to your activity in AndroidManifest? Also you can try another options which probably will suits better https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
This is an example of my second offer. To hide keyboard on EditText focus lose.
First you should create a onFocusChangeListener class.
public class KeyboardCloseListener implements View.OnFocusChangeListener {
private Activity activity;
public KeyboardCloseListener(Activity context) {
this.activity = context;
}
#Override
public void onFocusChange(View view, boolean b) {
if (!b)
closeKeyboard(view);
}
public void closeKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
Later you can use this class on all of your EditText fields.
In your activity you can use it like this:
KeyboardCloseListener keyboardCloseListener = new KeyboardCloseListener(this);
edittext.setOnFocusChangeListener(keyboardCloseListener);
Now it should work. If not, add these lines to your parent View:
android:focusable="true"
android:clickable="true"
I am using a ListView. When the list is empty the spinning circle is showing which I want.
But I also want a text above/bellow that circle that displays a message eg. Loading
Adding the following only shows the text but not the spinning circle
<?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:orientation="vertical" >
<ListView android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Loading...."
android:gravity="center"
android:layout_gravity="center"
</LinearLayout>
How can I have both?
Note: Not a ProgressDialog. The original ListView spinner + Text
Update:
If I add the following after the TextView the spinner breaks my list:
<ProgressBar
android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2" >
</ProgressBar>
Make your TextView height and width wrap_content instead of match_parent.
Just place textview and progressbar in a LinearLayout and the id of layout should be android:empty
<LinearLayout
android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading..."
/>
</LinearLayout>
I found few topics here on SO, but they are not what i'm searching. One of them is this one Android ListActivity - how to add a view below the ListView?
I know i can position a View (like button) at the footer of listview. That means desired View will position itself AFTER last view.
I want to know how to position a View at the end of the screen (Just below).
Please check two pictures below:
I want to do this in java code. Any ideas?
try the following code
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
>
</ListView>
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
Use a Relative Layout. Set the Height of Listview to the required height. Place the button relative to the listview at the button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<ListView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="TextView" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="122dp"
android:text="Button" />
</RelativeLayout>