how to scroll up layout when clicking on edit text - android

this is my layout with soft input mode and without soft input mode.
But main problem is when i click next from second last edit text, i want to show those two buttons and last edit text with soft input mode. Please help
my xml file is as follows
<?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="fill_parent"
android:background="#drawable/scroll_bg" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="521dp"
android:layout_marginBottom="60dp"
android:background="#drawable/bg" >
<com.deemtech.widgets.MenuLayout
android:id="#+id/menuTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txtCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="140dp"
android:gravity="center"
android:text="#string/customer_details"
android:textColor="#ffffff"
android:textSize="12sp" />
<EditText
android:id="#+id/editNameCustomerDetails"
style="#style/EditText"
android:layout_below="#+id/txtCustomerDetails"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:ems="10"
android:hint="NAME"
android:inputType="text" />
<RelativeLayout
android:id="#+id/innerLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="190dp"
android:background="#drawable/bg_create_account1x"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="8dp" >
<EditText
android:id="#+id/editEmailCustomerDetails"
style="#style/EditText"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentTop="true"
android:layout_marginTop="52dp"
android:ems="10"
android:hint="EMAIL ADDRESS"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editPhoneCutomerDetails"
style="#style/EditText"
android:layout_below="#+id/editEmailCustomerDetails"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="CONTACT NUMBER"
android:maxLength="12"
android:inputType="phone" />
<!--
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignRight="#+id/editPhoneCutomerDetails"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginBottom="60dp"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:hint="ADDITIONAL INFO"
android:inputType="text"
android:padding="10dp"
>
<requestFocus />
</EditText>
-->
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/editPhoneCutomerDetails"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginBottom="60dp"
android:layout_marginTop="8dp"
android:hint="ADDITIONAL INFO"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:singleLine="true"
android:gravity="top"
android:lines="3"
android:padding="10dp"
android:width="150dp" >
<requestFocus />
</EditText>
</RelativeLayout>
<Button
android:id="#+id/btnBackCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="448dp"
android:layout_toLeftOf="#+id/btnSubmitCustomerDetails"
android:background="#drawable/btn_back"
android:contentDescription="#string/app_name" />
<Button
android:id="#+id/btnSubmitCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/editNameCustomerDetails"
android:layout_marginTop="448dp"
android:background="#drawable/btn_submit"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</ScrollView>

In your case you cant simply "adjustResize" the window. Also as you only want to show the buttons when the last edit text is clicked.
So you can try this approach, not truly suggested but will work for your scenario:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainf);
findViewById(R.id.editAdditionalInfo).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(sampleMediaPlayer.this, "text", 700).show();
findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
findViewById(R.id.editAdditionalInfo).requestFocusFromTouch();
}
});
}

check this link
or try this android:windowSoftInputMode="adjustResize" in your activity in manifest file.

with the help of nimish's answer i finally got wat i wanted
editPhoneCustomerDetails.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
findViewById(R.id.editAdditionalInfo).requestFocusFromTouch();
//((ScrollView) findViewById(R.id.scrollView)).fullScroll(View.FOCUS_DOWN);
//findViewById(R.id.editPhoneCutomerDetails).requestFocusFromTouch();
// findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
}
return false;
}
});
findViewById(R.id.editAdditionalInfo).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//findViewById(R.id.btnBackCustomerDetails).setFocusable(true);
findViewById(R.id.btnBackCustomerDetails).requestFocusFromTouch();
findViewById(R.id.editAdditionalInfo).requestFocusFromTouch();
}
});

Related

Edittext requestFocus() dynamically not working

I have multiple Edittexts on action next I have added nextFocus values in the xml.
But one edit text is either visible or invisible based on the state of under age checkbox value. So I need to set focus on it afterr YYYY editext dynammically. But dynamically the requestFocus() is not working.
What I need to do on click of Next
This Email view is visible only when under 18 check box is unchecked.
What happends on next button click after YYYY edittext : control goes
to username Edittext. I cant use FocusNext in xml as the app crashes
whenever the email textview is GONE
dobYearEt.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("focus","on yyyy");
if (actionId == EditorInfo.IME_ACTION_DONE ||
actionId == EditorInfo.IME_ACTION_NEXT) {
Log.i("focus",isUnderAge+"");
if(isUnderAge){
username_reg_ev_dob_row.setFocusableInTouchMode(true);
username_reg_ev_dob_row.requestFocus();
}else{
// NOTHING HAPPENS
// email_ev.setFocusableInTouchMode(true);
// dobYearEt.clearFocus();
email_ev.requestFocus();
// InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// mgr.showSoftInput(email_ev, InputMethodManager.SHOW_IMPLICIT);
}
return false;
}
Xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/register"
android:layout_marginLeft="#dimen/sign_up_left_right_margin"
android:layout_marginRight="#dimen/sign_up_left_right_margin"
android:layout_marginTop="#dimen/sign_up_user_name_top_margin">
<!--<RelativeLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content">-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<EditText
android:id="#+id/firstname_ev"
style="#style/RegisterViewStyle"
android:hint=" FIRST NAME:"
android:textCursorDrawable="#null"
android:nextFocusForward="#+id/middle_ev"
android:nextFocusRight="#+id/middle_ev"
android:nextFocusDown="#+id/middle_ev"
android:nextFocusLeft="#+id/middle_ev"
android:nextFocusUp="#+id/middle_ev"/>
<View
android:layout_width="#dimen/sign_up_names_sep_width"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/middle_ev"
style="#style/RegisterViewStyle"
android:hint=" MIDDLE INITIAL:"
android:textCursorDrawable="#null"
android:nextFocusForward="#+id/lastname_ev"
android:nextFocusRight="#+id/lastname_ev"
android:nextFocusDown="#+id/lastname_ev"
android:nextFocusLeft="#+id/lastname_ev"
android:nextFocusUp="#+id/lastname_ev"/>
<View
android:layout_width="#dimen/sign_up_names_sep_width"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/lastname_ev"
style="#style/RegisterViewStyle"
android:hint=" LAST NAME:"
android:textCursorDrawable="#null"
android:nextFocusForward="#+id/dob_mm_et"
android:nextFocusRight="#+id/dob_mm_et"
android:nextFocusDown="#+id/dob_mm_et"
android:nextFocusLeft="#+id/dob_mm_et"
android:nextFocusUp="#+id/dob_mm_et"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/under18_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/raffle_blue_color"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/under18_tv"
android:text="I'm under 18 and/or don't have an email?"/>
</LinearLayout>
<LinearLayout
android:id="#+id/dob_parent_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--android:weightSum="2"-->
<LinearLayout
style="#style/RegisterViewStyle2"
android:id="#+id/dob_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_marginTop="#dimen/sign_up_field_sep_margin"
android:layout_weight="1"
android:orientation="horizontal">
<!--style="#style/RegisterViewStyle2"-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DOB:"
android:textColor="#color/edit_text_hint_color"
android:id="#+id/dob_label_tv"
/>
<!--<EditText-->
<!--android:id="#+id/dob_dd_et"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:background="#android:color/transparent"-->
<!--android:hint="_ _"-->
<!--android:textCursorDrawable="#null"-->
<!--android:inputType="number"-->
<!--android:maxLength="2"-->
<!--android:nextFocusForward="#+id/dob_mm_et"-->
<!--android:nextFocusRight="#+id/dob_mm_et"-->
<!--android:nextFocusDown="#+id/dob_mm_et"-->
<!--android:nextFocusLeft="#+id/dob_mm_et"-->
<!--android:nextFocusUp="#+id/dob_mm_et"/>-->
<EditText
android:id="#+id/dob_mm_et"
style="#style/RegisterViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="MM"
android:textCursorDrawable="#null"
android:inputType="number"
android:maxLength="2"
android:nextFocusForward="#+id/dob_dd_et"
android:nextFocusRight="#+id/dob_dd_et"
android:nextFocusDown="#+id/dob_dd_et"
android:nextFocusLeft="#+id/dob_dd_et"
android:nextFocusUp="#+id/dob_dd_et"/>
<TextView
android:textColor="#color/edit_text_hint_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" / "/>
<!--<EditText-->
<!--android:id="#+id/dob_mm_et"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:background="#android:color/transparent"-->
<!--android:hint="_ _"-->
<!--android:inputType="number"-->
<!--android:textCursorDrawable="#null"-->
<!--android:maxLength="2"-->
<!--android:nextFocusForward="#+id/dob_yyyy_et"-->
<!--android:nextFocusRight="#+id/dob_yyyy_et"-->
<!--android:nextFocusDown="#+id/dob_yyyy_et"-->
<!--android:nextFocusLeft="#+id/dob_yyyy_et"-->
<!--android:nextFocusUp="#+id/dob_yyyy_et"/>-->
<EditText
android:id="#+id/dob_dd_et"
style="#style/RegisterViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="DD"
android:inputType="number"
android:textCursorDrawable="#null"
android:maxLength="2"
android:nextFocusForward="#+id/dob_yyyy_et"
android:nextFocusRight="#+id/dob_yyyy_et"
android:nextFocusDown="#+id/dob_yyyy_et"
android:nextFocusLeft="#+id/dob_yyyy_et"
android:nextFocusUp="#+id/dob_yyyy_et"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" / "
android:textColor="#color/edit_text_hint_color"/>
<EditText
style="#style/RegisterViewStyle"
android:id="#+id/dob_yyyy_et"
android:layout_width="wrap_content"
android:textCursorDrawable="#null"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="YYYY"
android:inputType="number"
android:maxLength="4"
/>
<!--android:nextFocusForward="#+id/email_ev"-->
<!--android:nextFocusRight="#+id/email_ev"-->
<!--android:nextFocusDown="#+id/email_ev"-->
<!--android:nextFocusLeft="#+id/email_ev"-->
<!--android:nextFocusUp="#+id/email_ev"-->
</LinearLayout>
<EditText
android:id="#+id/email_ev"
style="#style/RegisterViewStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/sign_up_field_sep_margin"
android:layout_weight="1"
android:hint=" EMAIL:"
android:textCursorDrawable="#null"
/>
<!--android:nextFocusForward="#+id/password_reg_ev"-->
<!--android:nextFocusRight="#+id/password_reg_ev"-->
<!--android:nextFocusDown="#+id/password_reg_ev"-->
<!--android:nextFocusLeft="#+id/password_reg_ev"-->
<!--android:nextFocusUp="#+id/password_reg_ev"-->
<!--style="#style/RegisterViewStyle2"-->
<EditText
android:id="#+id/username_reg_ev_dob_row"
style="#style/RegisterViewStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/sign_up_field_sep_margin"
android:layout_weight="1"
android:hint=" USERNAME:"
android:textCursorDrawable="#null"
android:visibility="gone"
android:nextFocusForward="#+id/password_reg_ev"
android:nextFocusRight="#+id/password_reg_ev"
android:nextFocusDown="#+id/password_reg_ev"
android:nextFocusLeft="#+id/password_reg_ev"
android:nextFocusUp="#+id/password_reg_ev"/>
</LinearLayout>
<EditText
android:id="#+id/username_reg_ev"
style="#style/RegisterViewStyle2"
android:layout_below="#+id/email_ev"
android:layout_marginTop="#dimen/sign_up_field_sep_margin"
android:hint=" USERNAME:"
android:textCursorDrawable="#null"
android:nextFocusForward="#+id/password_reg_ev"
android:nextFocusRight="#+id/password_reg_ev"
android:nextFocusDown="#+id/password_reg_ev"
android:nextFocusLeft="#+id/password_reg_ev"
android:nextFocusUp="#+id/password_reg_ev"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/password_reg_ev"
style="#style/RegisterViewStyle2"
android:layout_below="#+id/username_reg_ev"
android:layout_marginTop="#dimen/sign_up_field_sep_margin"
android:hint=" PASSWORD:"
android:layout_marginRight="2dp"
android:textCursorDrawable="#null"
android:inputType="textPassword"
android:nextFocusForward="#+id/confirm_password_reg_ev"
android:nextFocusRight="#+id/confirm_password_reg_ev"
android:nextFocusDown="#+id/confirm_password_reg_ev"
android:nextFocusLeft="#+id/confirm_password_reg_ev"
android:nextFocusUp="#+id/confirm_password_reg_ev"/>
<EditText
android:id="#+id/confirm_password_reg_ev"
style="#style/RegisterViewStyle2"
android:layout_below="#+id/password_reg_ev"
android:layout_marginTop="#dimen/sign_up_field_sep_margin"
android:hint=" CONFIRM PASSWORD:"
android:textCursorDrawable="#null"
android:inputType="textPassword"
android:nextFocusForward="#+id/group_code_reg_ev"
android:nextFocusRight="#+id/group_code_reg_ev"
android:nextFocusDown="#+id/group_code_reg_ev"
android:nextFocusLeft="#+id/group_code_reg_ev"
android:nextFocusUp="#+id/group_code_reg_ev"/>
</LinearLayout>
<EditText
android:id="#+id/group_code_reg_ev"
style="#style/RegisterViewStyle2"
android:layout_below="#+id/confirm_password_reg_ev"
android:layout_marginTop="#dimen/sign_up_field_sep_margin"
android:textCursorDrawable="#null"
android:hint=" GROUP CODE(OPTIONAL):"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/terms_conditions_signup_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/raffle_blue_color"
/>
<TextView
android:id="#+id/terms_conditions_register_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/terms_conditions"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/register_btn_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/registration_message"
android:layout_marginBottom="6dp"
android:layout_marginTop="#dimen/sign_up_btn_top_margin"
android:background="#color/raffle_blue_color">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="#+id/register_tv"
android:padding="6dp"
android:text="REGISTER"
android:textColor="#android:color/white"
android:textSize="#dimen/sign_up_edit_text_size"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
I have referred to various solutions but nothing is working
Set next EditText focused and editable on KEY_DOWN
requestFocus not working
EditText request focus not working
requestFocus not working
What was happening is the I was returning false from onEditorAction- Hence the default editor action was also performed back to back and the focus instantly moved away from the email editText. Now I return true and the deafult action is not performed.Its working correctly now.
dobYearEt.setOnEditorActionListener(new EditText.OnEditor ActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("focus","on yyyy");
if (actionId == EditorInfo.IME_ACTION_DONE ||
actionId == EditorInfo.IME_ACTION_NEXT) {
Log.i("focus",isUnderAge+"");
if(isUnderAge){
username_reg_ev_dob_row.setFocusableInTouchMode(true);
username_reg_ev_dob_row.requestFocus();
}else{
email_ev.requestFocus();
}
return true ; // NOW WORKS
// return false;
}
U need two xml attributes also to achieve this:
android:focusable="true"
android:focusableInTouchMode="true"
Add them to the EditText as well as the parent layouts. By default these are false, so the focus is not given to the requested view.
Source: https://developer.android.com/reference/android/view/View.html#attr_android:focusable
After u show the EditText based on the checkbox selection, add the next and previous focus points dynamically in code.
Hope this helps.

Android: TextView alignment with respect to RadioGroup

Hi i'm trying to implement the following design (RadioGroup is parallel to TextView of rignt side)
for this requirement i wrote the bellow xml code
<RelativeLayout
android:id="#+id/rl_group_create_group_privacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_group_create_group_icon"
android:layout_marginTop="10dp"
android:background="#drawable/rl_bg_board_group_create_group"
android:padding="10dp" >
<TextView
android:id="#+id/tv_group_create_group_privacy"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="#string/group_create_new_group_privacy"
android:textColor="#color/Black"
android:textSize="15sp" />
<RadioGroup
android:id="#+id/rg_group_create_group_privacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tv_group_create_group_privacy"
android:orientation="vertical" >
<RadioButton
android:id="#+id/rb_group_create_group_public"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="#string/group_create_new_group_public"
android:textSize="12sp" />
<RadioButton
android:id="#+id/rb_group_create_group_closed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:checked="false"
android:text="#string/group_create_new_group_closed"
android:textSize="12sp" />
<RadioButton
android:id="#+id/rb_group_create_group_secret"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:layout_weight="1"
android:checked="false"
android:text="#string/group_create_new_group_secret"
android:textSize="12sp" />
</RadioGroup>
<RelativeLayout
android:id="#+id/rl_group_create_group_privacy_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/rg_group_create_group_privacy"
android:background="#color/White" >
<TextView
android:id="#+id/tv_group_create_group_public_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/group_create_new_group_public_desc"
android:textColor="#color/Black"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_closed_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_group_create_group_public_desc"
android:layout_marginTop="10dp"
android:text="#string/group_create_new_group_closed_desc"
android:textColor="#color/Black"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_secret_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_group_create_group_closed_desc"
android:layout_marginTop="10dp"
android:text="#string/group_create_new_group_secret_desc"
android:textColor="#color/Black"
android:textSize="12sp" />
</RelativeLayout>
</RelativeLayout>
But it changing the alignment according to the device like the following picture (Some times radio button at middle of textView and some times at starting of textView and some more times at end of textView). By implementing the design in layout-large, layout-small, layout-xlarge we can achieve this some how but i don't want to follow. So, how to implement first image design without following layout-large, layout-small, layout-xlarge
I hope this may helpful to you
<LinearLayout
android:id="#+id/rl_group_create_group_privacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_group_create_group_icon"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top">
<TextView
android:id="#+id/tv_group_create_group_privacy"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:padding="5dp"
android:text="Privacy"
android:textColor="#000000"
android:textSize="15sp" />
<RadioButton
android:id="#+id/rb_group_create_group_public"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tv_group_create_group_privacy"
android:checked="false"
android:gravity="center|start"
android:text="Public"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_public_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/rb_group_create_group_public"
android:padding="5dp"
android:text="group_create_new_group_public_desc"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top">
<RadioButton
android:id="#+id/rb_group_create_group_closed"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:checked="false"
android:text="Closed"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_closed_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/rb_group_create_group_closed"
android:padding="5dp"
android:text="group_create_new_group_closed_desc"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_group_create_group_privacy_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top">
<RadioButton
android:id="#+id/rb_group_create_group_secret"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:checked="false"
android:text="Secret"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_secret_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/rb_group_create_group_secret"
android:padding="5dp"
android:text="group_create_new_group_secret_desc"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
In Activity
final RadioButton rbPublic = (RadioButton) findViewById(R.id.rb_group_create_group_public);
final RadioButton rbCloses = (RadioButton) findViewById(R.id.rb_group_create_group_closed);
final RadioButton rbSecret = (RadioButton) findViewById(R.id.rb_group_create_group_secret);
rbPublic.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
rbCloses.setChecked(!isChecked);
rbSecret.setChecked(!isChecked);
}
}
});
rbCloses.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
rbPublic.setChecked(!isChecked);
rbSecret.setChecked(!isChecked);
}
}
});
rbSecret.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
rbCloses.setChecked(!isChecked);
rbPublic.setChecked(!isChecked);
}
}
});

Android transparent activity cannot make action in background activity

Hi I am working with android.I had created an app in which I had called second activity as intent and I make its background transparent.Second Activity contains a button and when click on it it shows a slidedrawer. After calling 2nd one I can view 1st activity because 2nd activity background is transparent.But How can I make an action even when the 2nd activity is also there ???
here is my code
1st activity
public class MainActivity5 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blah);
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intnt = new Intent(MainActivity5.this,
GestureActivity.class);
startActivity(intnt);
Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_SHORT).show();
}
});
}
}
2nd activity
public class GestureActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
Toast.makeText(getApplicationContext(), "library", Toast.LENGTH_LONG).show();
}
}
activity_main1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
style="#style/CustomTheme" >
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="330dip"
android:layout_height="450dip"
android:orientation="vertical"
android:content="#+id/content"
android:handle="#+id/handle" >
<ImageButton
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#fe6e6e"
android:id="#+id/content">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Form"
android:layout_marginLeft="170px"
android:textColor="#101010"
android:textStyle="bold"
android:textSize="20sp"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:text="User Name-"
android:textStyle="bold"
android:textColor="#480000"
android:textSize="18sp"/>
<EditText
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_marginLeft="40dp"
android:layout_toRightOf="#+id/textView2"
android:width="160px" >
</EditText>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/userName"
android:layout_marginTop="44dp"
android:text="Password - "
android:textStyle="bold"
android:textColor="#480000"
android:textSize="18sp"/>
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_alignLeft="#+id/userName"
android:inputType="textPassword"
android:width="160px" >
</EditText>
<Button
android:id="#+id/login"
android:layout_width="130px"
android:layout_height="wrap_content"
android:layout_below="#+id/password"
android:layout_marginRight="25dp"
android:layout_marginTop="38dp"
android:layout_toLeftOf="#+id/password"
android:text="Login" />
<Button
android:id="#+id/reset"
android:layout_width="130px"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/login"
android:layout_alignBottom="#+id/login"
android:layout_alignRight="#+id/password"
android:layout_marginRight="14dp"
android:text="Reset" />
</RelativeLayout>
</SlidingDrawer>
</LinearLayout>
is it possible to make both activity can run at the same time ???
No yaar you can't run both activities at the same time .You will get a clear idea about this if you know the activity lifecycle.
Below is the link which gives clear idea about activity lifecycle
http://developer.android.com/reference/android/app/Activity.html

Arrow key effect on android layout button-

I have three layout based buttons. I m developing this project for android stick so user will use keyboard.I want to show selected state when user navigate between buttons using arrow key same like we have in list/grid view. How can I add make button selected when user use keyboard?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="90dip"
android:id="#+id/linear_top_button"
android:orientation="horizontal"
android:paddingLeft="15dip"
android:gravity="center_vertical"
android:background="#041F34"
android:clickable="true"
android:focusable="true">
<TextView
android:id="#+id/date_text"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:text="06.56"
android:textColor="#475B6D"
android:typeface="sans"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center_vertical"/>
<TextView
android:id="#+id/day_text"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:paddingLeft="8dip"
android:text="Day"
android:textColor="#FFFFFF"
android:typeface="sans"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center_vertical"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="90dip"
android:orientation="horizontal"
android:paddingLeft="15dip"
android:id="#+id/linear_second_button"
android:gravity="center_vertical"
android:clickable="true"
android:background="#041F34"
android:layout_marginTop="2dip"
android:focusable="true">
<TextView
android:id="#+id/date_text"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:text="06.56"
android:textColor="#475B6D"
android:typeface="sans"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center_vertical"/>
<TextView
android:id="#+id/day_text"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:paddingLeft="8dip"
android:text="Day"
android:textColor="#FFFFFF"
android:typeface="sans"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center_vertical"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="90dip"
android:orientation="horizontal"
android:paddingLeft="15dip"
android:layout_marginTop="2dip"
android:id="#+id/linear_third_button"
android:gravity="center_vertical"
android:background="#041F34"
android:clickable="true"
android:focusable="true">
<TextView
android:id="#+id/date_text"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:text="06.56"
android:textColor="#475B6D"
android:typeface="sans"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center_vertical"/>
<TextView
android:id="#+id/day_text"
android:layout_width="wrap_content"
android:layout_height="70dip"
android:paddingLeft="8dip"
android:text="Day"
android:textColor="#FFFFFF"
android:typeface="sans"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center_vertical"/>
</LinearLayout>
_oneButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
_oneButton.setBackgroundColor(Color.parseColor("#163040"));//#163040//#041F34 n
_twoButton.setBackgroundColor(Color.parseColor("#041F34"));
_threeButton.setBackgroundColor(Color.parseColor("#041F34"));
Log.d("p","1"); //Never called!
}
}
);
_twoButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
_twoButton.setBackgroundColor(Color.parseColor("#163040"));//#163040//#041F34 n
_oneButton.setBackgroundColor(Color.parseColor("#041F34"));
_threeButton.setBackgroundColor(Color.parseColor("#041F34"));
Log.d("p","2"); //Never called!
}
}
);
_threeButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
_threeButton.setBackgroundColor(Color.parseColor("#163040"));//#163040//#041F34 n
_oneButton.setBackgroundColor(Color.parseColor("#041F34"));
_twoButton.setBackgroundColor(Color.parseColor("#041F34"));
Log.d("p","3"); //Never called!
}
}
);
Problem resolved by implementing onfocus listener.
_threeButton.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
_threeButton.setBackgroundColor(Color.parseColor("#163040"));//#163040//#041F34 n
_oneButton.setBackgroundColor(Color.parseColor("#041F34"));
_twoButton.setBackgroundColor(Color.parseColor("#041F34"));
}
});

EditText prints a letter twice

I know this is kinda silly and weird question, but its really bugging me. As my post subject says, when I enter a letter in the edit text its printing twice. I tried to find the issue, but couldn't. Here is my code,
changecode.xml
<EditText
android:id="#+id/oldcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/changecodetxt"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:hint="Enter Old Pass Code"
android:inputType="number"
android:password="true" />
<EditText
android:id="#+id/newcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/oldcode"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:hint="Enter New Pass code"
android:inputType="number"
android:password="true" />
<EditText
android:id="#+id/renewcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/newcode"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="25dp"
android:hint="Re-Enter New Pass code"
android:inputType="number"
android:password="true" />
<Button
android:id="#+id/savenewcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/button_style"
android:text="Update Code" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/savenewcode"
android:layout_below="#id/renewcode"
android:gravity="center" >
<ToggleButton
android:id="#+id/cc_togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textOff="123"
android:textOn="ABC!##" />
</LinearLayout>
In MainActivity.java
oldcode = (EditText) findViewById(R.id.oldcode);
newcode = (EditText) findViewById(R.id.newcode);
renewcode = (EditText) findViewById(R.id.renewcode);
savenewcode = (Button) findViewById(R.id.savenewcode);
cc_toggle = (ToggleButton) findViewById(R.id.cc_togglebutton);
cc_toggle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
boolean on = cc_toggle.isChecked();
if (on) {
oldcode.setInputType(InputType.TYPE_CLASS_TEXT);
newcode.setInputType(InputType.TYPE_CLASS_TEXT);
renewcode.setInputType(InputType.TYPE_CLASS_TEXT);
}
else {
oldcode.setInputType(InputType.TYPE_CLASS_NUMBER);
newcode.setInputType(InputType.TYPE_CLASS_NUMBER);
renewcode.setInputType(InputType.TYPE_CLASS_NUMBER);
}
}
});
Any kind of help or suggestion is much appreciated.

Categories

Resources