How to use scrollTo() with Spinner? - java

I'm working on my first Android project, which means that I'm not that familiar with Android and Java, and I want to move scroll of ScrollView after a user presses the button for next action (IME_ACTION_SEND). My codes are as follows.
activity_add.xml
It basically consists of TextView, EditText, NumberPicker, Spinner, Button. I want to move the scroll after IME_ACTION_SEND on EditText, so that the NumberPicker is centered on the screen.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/addActivity_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<LinearLayout
android:id="#+id/layout_activity_add"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_addItem"
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:textSize="40sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/formLayout"
android:layout_marginTop="50dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/title_editText"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="#string/hint_title"
android:singleLine = "true"
android:maxLength="20" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/formLayout3"
android:layout_marginTop="50dp">
<TextView
android:id="#+id/period_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_period"
android:layout_centerHorizontal="true" />
<NumberPicker
android:id="#+id/period_number_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/period_textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</NumberPicker>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/formLayout4"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_category"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_toStartOf="#+id/background_spinner"
android:layout_toLeftOf="#+id/background_spinner" />
<Spinner
android:id="#+id/background_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical">
</Spinner>
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button_submit"
android:layout_gravity="center_horizontal"
android:text="#string/label_submit" />
</LinearLayout>
</ScrollView>
AddItemActivity.java
I've just copied the part which I think is relevant.
public class AddSinceItemActivity extends ActionBarActivity {
EditText title;
Spinner spinner;
NumberPicker numberPicker;
String title_string;
ViewGroup linearLayout;
ScrollView addActivity_scrollview;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
addActivity_scrollview = (ScrollView) findViewById(R.id.addActivity_scrollview);
linearLayout = (ViewGroup) findViewById(R.id.layout_activity_add);
title = (EditText) findViewById(R.id.title_editText);
numberPicker = (NumberPicker) findViewById(R.id.period_number_picker);
spinner = (Spinner) findViewById(R.id.background_spinner);
/* For title */
title.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
// I think here is the most important part.
addActivity_scrollview.smoothScrollTo(0, numberPicker.getBottom());
}
return false;
}
});
}
}
For addActivity_scrollview.smoothScrollTo(0, numberPicker.getBottom());,
I've tried many possible codes, such as
addActivity_scrollview.smoothScrollTo(0, spinner.getTop());
addActivity_scrollview.smoothScrollTo(0, 300); (300 is just a random number)
addActivity_scrollview.smoothScrollBy(0, 300);
but the scroll is always stuck (it moves a little but it's always the same position with above codes) and the screen barely shows the selected number of NumberPicker. How can I achieve the goal to set scroll so that the screen shows the entire NumberPicker?

just add this line to your edittext code in xml :android:imeOptions="actionSend" and then just try this into your activityaddActivity_scrollview.smoothScrollTo(0, 480);

I should've added android:imeOptions="actionSend" to <EditText> in order to properly listen on onEditorAction(). I thought it'd be okay with android:singLine="true" because that option enabled "next" action on keyboard.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/title_editText"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="#string/hint_title"
android:singleLine="true"
android:maxLength="20"
android:imeOptions="actionSend" />

Related

How can I focus on a Button within a custom ListView

In my app it has a custom ListView'. The ListView contains an Image button. At the moment if the user is using an Android phone or tablet they can select and press this Button.
But if they are using for example a Firestick that uses a remote I can't select it. How can I make sure that I can scroll through my list but also make sure it scrolls through the buttons as well when using a remote?
My custom.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/titleapp"
android:textSize="20dp"
android:textColor="#drawable/button_textcolour"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="12dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/img" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/detail"
android:layout_margin="6dp"
android:textSize="15dp"
android:layout_below="#+id/titleapp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/img"
android:layout_toEndOf="#+id/img"
android:textColor="#drawable/button_textcolour"/>
<ImageView
android:layout_width="45dp"
android:padding="5dp"
android:id="#+id/img"
android:scaleType="fitCenter"
android:cropToPadding="true"
android:adjustViewBounds="true"
android:layout_height="45dp"
android:layout_alignBottom="#+id/detail"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/downloads"
android:id="#+id/downloadcounttext"
android:layout_below="#+id/detail"
android:layout_alignEnd="#+id/detail"
android:layout_marginRight="50dp"
android:textColor="#drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_marginLeft="5dp"
android:id="#+id/counterdl"
android:layout_below="#+id/detail"
android:layout_alignEnd="#+id/detail"
android:layout_marginEnd="37dp"
android:textColor="#drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/date_added"
android:id="#+id/dateaddedtxt"
android:layout_below="#+id/detail"
android:layout_alignStart="#+id/detail"
android:textColor="#drawable/button_textcolour"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="01/01/0000"
android:id="#+id/datetext"
android:layout_below="#+id/detail"
android:layout_toEndOf="#+id/dateaddedtxt"
android:textColor="#drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report?"
android:paddingRight="5dp"
android:layout_alignTop="#+id/img"
android:layout_toStartOf="#+id/report"
android:layout_alignParentTop="true"
android:layout_margin="5dp" />
//HERE I WANT THIS BUTTON ON EVERY ITEM TO BE ABLE TO GAIN FOCUS WITH IN THE LIST
<ImageButton
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/report"
android:background="#drawable/ic_sentiment_dissatisfied_black_24dp"
android:layout_alignEnd="#+id/detail" />
My method in my BaseAdapter that allows selection of the button:
public View getView(final int position, View convertView, ViewGroup parent) { final View row;
if (convertView == null) {
row = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom, parent, false);
} else {
row = convertView;
}
report = row.findViewById(R.id.report);
report.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
title.setText(Title[position]);
String getappname = title.getText().toString();
if (getappname!= null){
Log.i("Bad App ", getappname);

Avoid clicking of full layout

I only want my textview with id clickable_txtView to be clickable in relative layout. Here is the code -
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#android:id/empty"
android:clickable="false">
<ImageView
android:layout_width="120sp"
android:layout_height="130sp"
android:layout_centerHorizontal="true"
android:src="#drawable/flower"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="120sp"
android:text="Dont click me />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/clickable_txtView"
android:gravity="center"
android:paddingTop="140sp"
android:clickable="true"
android:text="Click me" />
</RelativeLayout>
#OnClick(R.id.clickable_txtView)
public void txtViewClick() {
//Some event
}
Thr problem is I am able to click whole relative layout and some event happens after onclicking relative layout.
How do I avoid this and make it limited to text view only.
Your textview has an attribute android:paddingTop="140sp" which basically wraps over the entire relative layout, because of which you are having the problem with onClick behaviour.
Use this RelativeLayout structure (provide ID to the "don't click me" textview, and place the "clickable textview" below it.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:layout_width="120sp"
android:layout_height="130sp"
android:layout_centerHorizontal="true"
android:src="#mipmap/ic_launcher"
android:layout_alignParentTop="true"
/>
<TextView
android:id="#+id/do_not_click"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="120sp"
android:enabled="false"
android:text="Dont click me" />
<TextView
android:id="#+id/clickable_txtView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:layout_below="#id/do_not_click"
android:text="Click me" />
</RelativeLayout>
In your activity where you are inflating this view try this:
first initialize your textview
TextView textView = (TextView) findViewById(R.id.clickable_txtView);
then apply clickListner on it
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Do your work here
}
});
I'm not sure but you can try adding below line to your parent layout
android:touchscreenBlocksFocus="true"
like
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#android:id/empty"
android:touchscreenBlocksFocus="true">

How can I make better custom dialogs?

I'm creating a game and in it I use a lot of dialogs. The dialogs make up the main menu in a more simple setup then making up an entire activity for it. These dialogs though, they have a grey outline which is really annoying, and in addition when going from one dialog to another, it shrinks down and blows up as one dissapears and another one reappears.
How can I remove the outline and make the transition more smooth? If it is not possible with dialogs, what can an alternative be? I am using custom layouts connected to Java classes that extend Dialog
EDIT
Java:
public class MenuDialog extends Dialog implements View.OnClickListener {
Context con;
Clicker c;
public MenuDialog(Context c, Clicker game) {
super(c);
this.con = c;
this.c = game;
Window window = this.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
show();
}
Button stat, gem, cash, shop, powerup, settings;
#Override
protected void onCreate(Bundle sis){
super.onCreate(sis);
setContentView(R.layout.menu);
setButtons();
}
private void setButtons(){
stat = (Button) findViewById(R.id.bStats);
gem = (Button) findViewById(R.id.bGems);
gem.setOnClickListener(this);
stat.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bStats:
StatDialog sd = new StatDialog(con,c);
sd.show();
break;
case R.id.bGems:
IAPDialog iapd = new IAPDialog(con, c);
iapd.show();
break;
//other buttons
}
dismiss();
}
}
XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:id="#+id/relativeLayout"
android:gravity="center_horizontal"
android:background="#drawable/phone_like_bc"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearLayout5"
android:layout_marginTop="51dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bStats"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/bGems"
android:background="#drawable/stat_button"
android:layout_toStartOf="#+id/bGems" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/stats"
android:id="#+id/textView17"
android:layout_below="#+id/bStats"
android:layout_alignLeft="#+id/bStats"
android:layout_alignStart="#+id/bStats" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/bShop"
android:background="#drawable/shop"
android:layout_below="#+id/textView17" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/shop"
android:textAlignment="center"
android:id="#+id/textView18"
android:layout_alignTop="#+id/textView16"
android:layout_alignLeft="#+id/bShop"
android:layout_alignStart="#+id/bShop" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearLayout"
android:layout_marginTop="51dp"
>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/gem"
android:id="#+id/bGems"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/linearLayout5"
android:layout_toEndOf="#+id/linearLayout5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/gems"
android:id="#+id/textView15"
android:layout_alignBaseline="#+id/textView20"
android:layout_alignBottom="#+id/textView20"
android:layout_toLeftOf="#+id/bPowerUp"
android:layout_toStartOf="#+id/bPowerUp"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/bPowerUp"
android:background="#drawable/lightning"
android:layout_alignTop="#+id/linearLayout"
android:layout_toLeftOf="#+id/bSettings"
android:layout_toStartOf="#+id/bSettings" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/powerups"
android:id="#+id/textView16"
android:layout_alignBaseline="#+id/bSettings"
android:layout_alignBottom="#+id/bSettings"
android:layout_toLeftOf="#+id/bSettings"
android:layout_toStartOf="#+id/bSettings" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="51dp"
android:gravity="center">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/bCash"
android:background="#drawable/cash"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:text=" " />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/cash"
android:id="#+id/textView19"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/bSettings"
android:background="#drawable/settings"
android:layout_below="#+id/bCash"
android:layout_alignLeft="#+id/bCash"
android:layout_alignStart="#+id/bCash" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/settings"
android:id="#+id/textView20"
android:layout_alignBottom="#+id/bCash"
android:layout_alignLeft="#+id/textView19"
android:layout_alignStart="#+id/textView19" />
</LinearLayout>
</LinearLayout>
There are two more dialog classes both XML and java. I added those two to show that I already know how to add the classes, but I need to know how to remove the outline of the dialog and I need to know how I can smoothen the transition between two dialogs. They have the same background too.
You can use DialogFragments instead of Dialogs, they works as Fragments and you can customize them. Read more about the use of Dialog fragments at https://developer.android.com/reference/android/app/DialogFragment.html
You have a lot of Tutorials to create your own DialogFragments in Google if you don't like the Android Documentation.

TextInputLayout not animating when OnFocusChangeListener applied to wrapped EditText

Can't say it much more clearly than in the title. I have an EditText wrapped by a Text Input Layout. I'm trying to trigger an event when that EditText loses focus. However, once the event listener is applied, the TextInputLayout no longer animates the text, it just sits on the editText line until information is entered, at which time it does animate. Can anyone give me some insight as to why this is happening?
Edit: Layout file.
<?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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/card_drawable"
android:gravity="center"
android:padding="11dp"
android:text="The fields below will be used to calculate your training maxes. Please enter your best rep record, or 1RM, for each lift. Training maxes will be determined using the following formula provided in Beyond 5/3/1: \n(Weight Lifted x Reps X .0333 + Weight Lifted)" />
<LinearLayout
android:id="#+id/squat_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/squatWeight_editText"
style="#style/editText_floating_label"
android:hint="Squat Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/txtInputLayoutSquat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/squatReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bench_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/bechpressWeight_editText"
style="#style/editText_floating_label"
android:hint="Bench Press Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/benchpressReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/deadlift_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/deadliftWeight_editText"
style="#style/editText_floating_label"
android:hint="Deadlift Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/deadliftReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ohp_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/ohpWeight_editText"
style="#style/editText_floating_label"
android:hint="Overhead Press Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/ohpReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
I had to deal with the same issue.
The workaround I used was using a custom EditText and adding a custom listener to it to be called when the onFocusChanged method is fired.
Custom EditText (Boiler plate code is not shown)
public class EditTextPlus extends AppCompatEditText {
//This is the custom listener you will use
public OnFocusChangeListener customListener;
#Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (customListener != null) {
customListener.onFocusChange(this, focused);
}
}
}
In Activity/Fragment
yourEditText.customListener = new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
//Do your stuff
}
}
Don't forget to use the custom EditText in the xml as well and not the default EditText.
This doesn't solve the issue but does give some insight (I'll update if I figure out a solution), but seems like the animated hint is dependent on OnFocusChangedListener, which gets overwritten when you add your own listener.
https://code.google.com/p/android/issues/detail?id=175344
EDIT:
Per https://code.google.com/p/android/issues/detail?id=178693...
We're now using a different way to determine if the EditText is focused. For now do something like:
TextInputLayout inputLayout = ...;
EditText editText = inputLayout.getEditText();
final OnFocusChangeListener existing = editText.getOnFocusChangeListener();
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean focused) {
existing.onFocusChange(view, focused);
// Your custom logic
}
});

Android Emulator Result display

I have created an simple app which has string input(edit text) and displays the string on click of the button using text view. I have used vertical scroll view, The problem is right side characters hidden. Here is the code I used
public class MainActivity extends Activity {
TextView text;
EditText txt;
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)findViewById(R.id.dis);
txt = (EditText)findViewById(R.id.mesg);
btn = (Button)findViewById(R.id.button);
}
public void Display(View v) {
String msg=txt.getText().toString();
text.setText(msg);
//text.setText("yes");
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff000000"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:baselineAligned="true"
android:gravity="bottom" >
<TableRow android:padding="10dp" >
<EditText
android:id="#+id/mesg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:ems="10"
android:hint="Message"
android:text="" >
</EditText>
</TableRow>
<TableRow android:padding="10dp" >
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Display"
android:text="Dispaly" />
</TableRow>
<TableRow android:padding="10dp" >
<TextView
android:id="#+id/dis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#ffffff" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
As you see the 's' in says is hidden and also sometimes it happens with text view
Try this..
Add padding like android:padding="5dp" to EditText
<EditText
android:id="#+id/mesg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:padding="5dp"
android:ems="10"
android:hint="Message"
android:text="" >
</EditText>
Remove the android:ems directive from your EditText.

Categories

Resources