I want to scroll a android screen dynamically by clicking a button. The scrollable content will be added dynamically. The screen shot i have attached. As shown in the screen shot i want to scroll the screen like the "Car details" label should be at the top of the screen.
sv.post(new Runnable()
{
#Override
public void run()
{
sv.fullScroll(View.FOCUS_DOWN);
vehicle_no.setFocusableInTouchMode(true);
vehicle_no.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(vehicle_no, InputMethodManager.SHOW_IMPLICIT);
}
});
This is the code that i am using to scroll the screen. But it's not solving my problem. Please suggest me a solution for this problem. Thank you.
Add car details
First add view and then call this
sv.postDelayed(new Runnable()
{ #Override
public void run()
{ your code } },500);
Related
I have a scrollView in which while I am at end of the scrollView, on clicking a button at the end I need to show a view below that button. I am doing it by changing the visibility of that newly added view from GONE to VISIBLE. Its working but after clicking the button I am not able to see the newly added view i.e I need to scroll down the scrollView to show that view. Is there a way to scroll the ScrollView to that newly added view after clicking the button? and also to hide that view and scroll back to normal state after clicking that button again.
Thanks in advance!
it's an alternative which pretty much does the same thing.
Instead of Scrolling to the bottom of the screen, change the focus to a view which is located at the bottom of the screen.
That is, Replace:
scroll.scrollTo(0, scroll.getBottom());
with:
Footer.requestFocus();
Make sure you specify that the view, say 'Footer' is focusable.
android:focusable="true"
android:focusableInTouchMode="true"
or if above is not working try this
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
As the view that i was adding at the end was added with an expand animation so i used a countdown timer for it as follows:
new CountDownTimer(500, 1) {
public void onTick(long millisUntilFinished) {
myScrollView.scrollTo(0, R.id.bottomView);
}
public void onFinish() {
}
}.start();
Thats all.
I have two buttons Button 1, Button 2 placed horizontally like tabs. On Click of these button I am adding Linear Layout in Scroll View.
Now suppose I am clicking Button 1 and scroll down and immediately switch or click to Button 2 that scroll applies on newly added layout. I want every time on click of button content should scroll to top.
I have tried scrollview.scrollT0(0,0) and scrollview.scrollTo(0,scrollview.getTop()) but none of them is working.
I've ran into these types of issues before.
I suggest trying the following:
scrollview.post(new Runnable() {
#Override
public void run() {
scrollview.scrollTo(0, 0);
}
});
The reason this works is forces the action in the Main Thread which is where all UI Activity happens (safely, of course).
Try this . Just it is sample
private void scrollMyListViewToBottom() {
your_list.post(new Runnable() {
public void run() {
if (!running) {
// Select the last row so it will scroll into view...
your_list.setSelection(your_list.getCount() - 1);
running = true;
}
}
});
Note :
Before call this method just change Boolean running = false;
How to show my layout in front off soft keyboard Android like whatsapp or facebook?
like this
thanks before
this my code, but when emoji layout show, soft keyboard close.
btn_pop_emot.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (listEmot.getVisibility() == View.VISIBLE) {
listEmot.setVisibility(View.GONE);
imm.toggleSoftInputFromWindow(
edt_pop_komen.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
btn_pop_emot.setBackgroundResource(R.drawable.emot_anim);
} else {
listEmot.setVisibility(View.VISIBLE);
imm.hideSoftInputFromWindow(edt_pop_komen.getWindowToken(),
0);
btn_pop_emot.setBackgroundResource(R.drawable.keyboard);
}
}
});
You can use this library, it also contains sample code in README to get you started
https://github.com/ankushsachdeva/emojicon
I've browsed similar questions and followed the suggestions there, but for the love of god, I can't get this to work, and it's driving me crazy. So here's the deal:
I have an editText, which needs to requestFocus at program startup, and pop the soft keyboard. If I put "android:windowSoftInputMode="stateVisible" in the Manifest, the keboard shows every time the activity starts. I only want it to show once with onCreate(), and when the user specifically clicks on the editText. My code for this is below:
EditText argument;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio_buttons);
argument = (EditText) findViewById(R.id.editText_argument);
InputMethodManager imm = InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(argument, InputMethodManager.SHOW_FORCED);
Q1) This code doesn't work. What am I doing wrong?
Q2) You see that I declared "EditText argument" outside of onCreate(), as I'd like to use this in the rest of the activity, not just within onCreate(). Is this good programming practice?
Q3) Then, when the user clicks done on the soft keyboard, I'd like this EditText to lose focus, i.e. the cursor should disappear. I understand that I need to have a dummy View to do this, but I still don't exactly understand how to switch focus to the dummy. How would I go about doing that?
Thanks so much in advance!
A1) You're missing a editText.requestFocus().
Refer: Soft Keyboard shows up on EditText focus ONLY once should help for dismissing soft keyboard.
A2) Yes, that's fine. Most of the UI elments should be declared at the class level scope and initialized in onCreate()
A3) A1's reference link should help you here.
Happy Coding!
EDIT:
onCreate():
EditText argument;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio_buttons);
argument = (EditText) findViewById(R.id.editText_argument);
showKeyboard():
argument.requestFocus();
argument.postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(argument, 0);
}
},200);
dismissKeyboard():
argument.requestFocus();
argument.postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.hideSoftInputFromWindow(argument.getWindowToken(), 0);
}
},200);
so I tried android:selectAllOnFocus and of course I'm using android:hint.
The app loads, requestFocus triggers and the full text is selected.
The problem is that when I click in the EditText the selection is lost.
I've already read:
Select all text inside EditText when it gets focus
For some reason, it worked (on Jelly Bean) only if I posted it with a Handler:
new Handler().post(new Runnable() {
#Override
public void run() {
paidView.selectAll();
}
});
Set the selection in an View.OnClickListener like so:
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editText.setSelection(0, editText.getText().length() - 1);
}
}
Set the selection in an View.OnClickListener like so: (with the 0 and text length opposite to the previously approved response) - this will ensure that when the user starts typing the content will be overridden.
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editText.setSelection(editText.getText().length() - 1, 0);
}
}
I realize this is an old post, but I had this same problem. For me, the reasoning was that I like to move the keyboard out of the way (dismiss it) to get my bearings (or hit buttons to add or remove rows of data) and when i touched back on the EditText I was previously editing, it was annoying to have the keyboard pop back up and the text un-select, forcing me to either work to get the cursor to where I wanted to start deleting, or touch another EditText and then touch back on the original to re-select everything. I just want to have the keyboard pop back up and have the text selected and ready to overwrite whenever I go to that EditText.
There are easy solutions to this:
1) Long tap does this for you on most occasions.
2) If you're already using setSelectAllOnFocus(true), you can just throw a simple clearFocus() and requestFocus() in your onClick listener:
etMyEditText.setSelectAllOnFocus(true);
etMyEditText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
view.clearFocus();
view.requestFocus();
}
});
This way the EditText has everything selected when you tap on it, regardless of soft keyboard status.
Additional bonus:
Add android:windowSoftInputMode="adjustPan" inside your <activity .../> tag in your AndroidManifest.xml file to force the selected EditText to stay in sight when the soft keyboard pops up.
try This
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editText.selectAll();
//or this.selectAll();
}
To select all the text.
Do the code below after you did findViewById and you are good to go:
edtProductPrice.setSelectAllOnFocus(true);
edtProductPrice.requestFocus();
edtProductPrice.selectAll();