Softwindow keyboard hides the edittext - android

i am inflating the layout using the layout inflator which had 10 editext field, when i click on the edittext soft keyboard hides the edittext if me does not inflate the layout and place in the setcontentview it workis fine. if a put requestfocus tag with inflating the layout crash the app. please find the below code and help me to resolve this.
JAVA CODE
LayoutInflater inflater = LayoutInflater.from(this);
scrollView = (MyHorizontalScrollView)
inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
setContentView(scrollView);// if i comment this and add inflatelayout SetContentView(R.layout_details) works fine.
menu = inflater.inflate(R.layout.horz_scroll_menu, null);
app = inflater.inflate(R.layout.details, null);//

You may need to change an attribute in your manifest (for your Activity) to handle this. Put this line in your AndroidManifest.xml (within the tag you use to define your Activity)
android:windowSoftInputMode="adjustResize"

Related

Unable to inflate a layout on button click

Hi I am trying to show a layout when a button is pressed but the layout is never shown. No exception is thrown for some reason. The button is located inside an activity. The button is called and declared and it works. The calling of the layout is just additional action to the button.
Here is my code to inflate the layout:
LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View error = layoutInflater.inflate(R.layout.error_search_no_results,null);
Use this :
rv.addView(error);
Where rv is your parent layout.

Android including an xml layout to activity

I've an activity.java file in which my setContentView(R.layout.x); Now,I've an y.xml in which I've an Linear Layout,I've to attach an onclick() method to my view.
Attaching onclick() has to be in my activity.java file, How do I include y.xml.
I tried this,
1. layout = (LinearLayout) findViewById(R.layout.y);
eView = (EditText)layout. findViewById(R.id.editview);
2. eView = (EditText)findViewById(R.id.editview);
but both gives my null pointer exception, How do I include my editText
Update
final LayoutInflater lyInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
showLinearLayout = (LinearLayout) lyInflater.inflate(R.layout.y, null);
showView = (EditView) showLinearLayout.findViewById(R.id.edittext);
You can use inflation as shown below:
final LayoutInflater lyInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout yLayout = (LinearLayout) lyInflater .inflate(
R.layout.y, null);
eView = (EditText)yLayout.findViewById(R.id.editview);
So you won't get exception anymore. Hope it helps.
LayoutInflater is used to instantiate layout XML file into its corresponding View objects.in other words, it takes as input a XML file and builds the View objects from it.
in your scenario, you have to use LayoutInflater. read this article.
Ram.
If you want to include y xml file into your x xml file then follw this steps.
I am assuming that you want to include Linear Layout into your Activity on click of onclick() method of the button or whatever, then add the Linear Layout into your x xml file and add the android:visibility="gone" so at begin you can not show the linearlayout.
<LinearLayout
android:id="#+id/history_value_body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" > <<<<<<<<<<< HERE
----------------------------
-----------------------------
</LinearLayout>
Now, From the java class make it visible when needed, in your case into onclick method.
Like...
linear.setVisibility(View.VISIBLE); // linear is the object of your Linearlayout
If any prob then ask me.
Good Luck.
If I understand the question correctly, your Activity uses x.xml, and you also want to include another layout that is defined in y.xml.
You can do so using the <merge> or <include> tags, as described in the documentation.
Alternately, you can use a ViewStub to conditionally inflate another layout in a given place in a layout. For example, you can include a ViewStub tag in x.xml, and inflate y.xml in the same spot in the view hierarchy. Then, you may attach any click listeners you need (by using findViewById()).
You can use addView method of ViewGroup.
addView(layout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

Dynamically add layout on button click and get text from the layout?

So I have a layout that gets added to the main layout every time the user presses a button. I got that working fine, but that layout happens to consist of several EditTexts. What would be the best way to get the text from the EditText? I only have the id of the layout itself, not the EditTexts inside the layout.
I thought of just adding EditTexts dynamically one by one, but is there a more efficient way of doing it? I'd much rather just inflate an xml layout every the button is clicked.
I assume you're adding new views by inflating them and then adding them to the main view similar to below.
LinearLayout newView = (LinearLayout)this.getLayoutInflater().inflate(R.layout.my_layout, null);
LinearLayout mainView = (LinearLayout)this.findViewById(R.id.mainLayout);
mainView.addView(newView);
You can use findViewById() on the newView to access each EditText as required.
EditText editText = (EditText) newView.findViewById(R.id.myButton);
String text = editText.getText().toString();
Since it's a fixed layout you inflate from a particular XML file, you can also use getChildAt(int index) to find a particular view of the ViewGroup.

how to change the inflater of my KeyboardView

I am developing an IME for android.
i have the options of setting the theme for the keyboard.
the problem when i try to inflate the keyboardView a second time it it did not work
KeyboardView k = (KeyboardView) getLayoutInflater().inflate(R.layout.input1, null);
it change just when i re-runing the app .
it seems is just changed when the my InputMethodeService recreated but i did not found a way to stop it and start the service again.
Plz Help
I found a solution to my problem.
My real problem is to inflate the same view ( KeyboardView ) multiple time.
I tried to change my parent view from KeyboardView to a RelativeLayout and for each keyboardveiw Theme i Remove all the parent child and i add the new keyboardview infalted with the new Theme.

set LayOut Dynamically

i want to add Layout Dynamically on Add button click and on Dynamic Layout show Datepicker,Timepicker Dialog and set value in given Edit Text. show in image on Date Click set Date Right side . Here problem Start when Add Second Same layout and set date it set only on newly created layout
For example you need to create xml layout file with ScrollView and LinearView inside.
Then in your Activity class:
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View main = inflater.inflate(R.layout.your_layout, null);
setContentView(main);
LinearLayout linear = (LinearLayout)main.findViewById(R.id.linear_layout);
and then in onClick method just:
View yourView = inflater.inflate(R.layout.yourView, null);
// Do whatever you want with your View, set up some variables etc.
and to add your view to main view:
linear.addView(yourView);
I know that this is not a direct answer to your question, but maybe will help you with dynamically adding Views.

Categories

Resources