I have this DialogFragment. When I show it, it becomes fullscreen, I mean it overlaps the current screen. How to make it small like an AlertDialog?
I guessed it's because of the RelativeLayout so I wrapped the LinearLayout outside of RelativeLayout but nothing changes.
public class LoginDialogFragment extends DialogFragment {
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme);
}
#Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.login_dialog, container, false);
final EditText emailEditText = (EditText)v.findViewById(R.id.emailEditText);
final EditText passwordEditText = (EditText)v.findViewById(R.id.passwordEditText);
final Button loginButton = (Button)v.findViewById(R.id.loginButton);
loginButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(final View v) {
checkLogin(emailEditText.getText().toString(), passwordEditText.getText().toString());
}
});
return v;
}
}
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/loginTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/loginDialogTitle"
android:textColor="#color/White"
android:textSize="20sp" />
<EditText
android:id="#+id/emailEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/loginTitleTextView"
android:layout_weight="1"
android:ems="10"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/passwordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/emailEditText"
android:layout_weight="1"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="#+id/passwordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/passwordEditText"
android:layout_alignBottom="#+id/passwordEditText"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:text="#string/password"
android:textColor="#color/White"
android:textSize="16sp" />
<TextView
android:id="#+id/emailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/emailEditText"
android:layout_alignBottom="#+id/emailEditText"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:text="#string/email"
android:textColor="#color/White"
android:textSize="16sp" />
<Button
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/passwordEditText"
android:text="#string/loginButtonText" />
</RelativeLayout>
</LinearLayout>
Call setStyle(STYLE_NORMAL, android.R.style.Theme_Dialog); instead of setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme); in onCreate(). Did it help?
Related
I have button on my activity that show up on the fragment and only the button that show up , i did search about it and find out its a rendering issue but the answers didn't worked for me, here how it looks.
Fragment
Activity
is there any chance that the issue code be from the margin of the button
Fragment.java
public class Smsar extends Fragment {
public Smsar() {
// Required empty public constructor
}
View root;
Button mSmsar,mFinder;
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
root= inflater.inflate(R.layout.fragment_smsar, container, false);
mSmsar=(Button)root.findViewById(R.id.smsar);
mFinder=(Button)root.findViewById(R.id.finder);
mSmsar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
mFinder.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Open Discover.
}
});
return root;
}
}
Fragment XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_background_difference"
tools:context=".Smsar">
<!-- TODO: Update blank fragment layout -->
<Button
android:id="#+id/smsar"
android:layout_width="250dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="59dp"
android:background="#drawable/btn_rounded"
android:fontFamily="#font/cabin"
android:text="Smsar ?"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="18sp"
android:typeface="normal" />
<Button
android:id="#+id/finder"
android:layout_width="204dp"
android:layout_height="63dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="138dp"
android:background="#drawable/btn_rounded"
android:fontFamily="#font/cabin"
android:text="Want Apartment ?"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
</RelativeLayout>
Activity XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical"
tools:context=".MainActivity"
android:id="#+id/mainView"
>
<ImageView
android:id="#+id/logo"
android:layout_width="162dp"
android:layout_height="196dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:adjustViewBounds="true"
android:maxHeight="64dp"
android:maxWidth="64dp"
app:srcCompat="#drawable/logo" />
<Button
android:id="#+id/logIn"
android:layout_width="218dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/userName"
android:layout_alignParentBottom="true"
android:layout_marginEnd="31dp"
android:layout_marginBottom="113dp"
android:background="#color/buttons"
android:clickable="true"
android:fontFamily="#font/catamaran"
android:onClick="logIN"
android:text="Login"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textSize="22sp" />
<EditText
android:id="#+id/userName"
android:layout_width="277dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ems="10"
android:fontFamily="#font/catamaran"
android:hint="UserName"
android:inputType="textPersonName"
android:text="" />
<EditText
android:id="#+id/password"
android:layout_width="277dp"
android:layout_height="wrap_content"
android:layout_below="#+id/userName"
android:layout_centerHorizontal="true"
android:fontFamily="#font/catamaran"
android:hint="Password"
android:inputType="textPassword" />
<TextView
android:id="#+id/_new"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginEnd="-35dp"
android:layout_marginBottom="0dp"
android:layout_toStartOf="#+id/sginUp"
android:fontFamily="#font/catamaran"
android:text="New ? Start Now By"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="#+id/sginUp"
android:layout_width="81dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="17dp"
android:layout_marginBottom="0dp"
android:layout_centerHorizontal="true"
android:layout_toEndOf="#id/mError"
android:clickable="true"
android:fontFamily="#font/catamaran"
android:text="SginUp"
android:textAlignment="center"
android:textColor="#color/links"
android:textSize="18sp" />
<TextView
android:id="#+id/mError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="82dp"
android:textColor="#android:color/holo_red_dark"
android:visibility="invisible"
android:text="mError" />
</RelativeLayout>
Activity.Java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_login =(Button)findViewById(R.id.logIn);
pref = getSharedPreferences("user_details", MODE_PRIVATE);
if(pref.contains("username")&&pref.contains("password"))
success();
FragmentManager fm=getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.addToBackStack(null);
ft.replace(R.id.mainView, mFrag);
ft.commit();
imageView=(ImageView)findViewById(R.id.logo);
mDBHelper =new DBHelper(this);
mError=(TextView)findViewById(R.id.mError);
//Define the variables
userNameEdit=(EditText)findViewById(R.id.userName);
passwordEdit=(EditText)findViewById(R.id.password);
_signUp=(TextView)findViewById(R.id.sginUp);
//End
_signUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
intent=new Intent(MainActivity.this,Signup.class);
startActivity(intent);
}
});
}
I solve it by surround the button with LinearLayout
<LinearLayout
android:id="#+id/buttonContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/password"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
>
<Button
android:id="#+id/logIn"
android:layout_width="186dp"
android:layout_height="wrap_content"
android:layout_marginVertical="12dp"
android:background="#drawable/btn_rounded"
android:minWidth="200dp"
android:onClick="logIN"
android:text="#string/title_login"
android:textAllCaps="false"
android:textColor="#color/ms_white"
android:textSize="18sp" />
</LinearLayout>
I have a fragment in my activity. I'm trying to make RelativeLayout clicable in fragment but when I click it's not working, nothing happens.
activity_main.xml:
<RelativeLayout
android:padding="5.0dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15.0dip"
android:layout_marginTop="15.0dip"
android:layout_marginRight="15.0dip"
android:layout_marginBottom="5.0dip"
android:layout_below="#+id/header2">
<FrameLayout
android:id="#+id/frameCoin"
android:background="#color/colorTransparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
fragment_main.xml:
<RelativeLayout
android:id="#+id/relative500coin"
android:background="#drawable/buttons_bg"
android:padding="5.0sp"
android:layout_width="fill_parent"
android:layout_height="70.0dip"
android:layout_marginBottom="10.0dip"
android:focusable="true">
<ImageView
android:id="#+id/coin500Image"
android:layout_width="38.0dip"
android:layout_height="38.0dip"
android:layout_marginStart="16.0dip"
android:src="#drawable/coin_count_image"
android:tint="#color/colorWhite"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="38.0dip"
android:layout_toEndOf="#+id/coin500Image"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true">
<TextView
android:textSize="20.0sp"
android:textStyle="bold"
android:textColor="#ffffffff"
android:paddingLeft="15.0dip"
android:paddingRight="15.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0.0dip"
android:text="#string/coin_500"
android:layout_alignParentTop="true"
tools:ignore="RelativeOverlap" />
<TextView
android:textSize="12sp"
android:textColor="#ffffffff"
android:paddingLeft="15.0dip"
android:paddingRight="15.0dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coin_500_text"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coin_500_price"
android:textSize="25sp"
android:textStyle="bold"
android:layout_marginEnd="10sp"
android:textColor="#color/colorWhite"
android:tint="#ffffffff"
android:layout_alignParentEnd="true"
tools:ignore="RelativeOverlap" />
</RelativeLayout>
</RelativeLayout>
Fragment.java:
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_main, container, false);
RelativeLayout relative500coin = view.findViewById(R.id.relative500coin);
relative500coin.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
bp.consumePurchase("coin_500");
bp.purchase(getActivity(), "coin_500");
}
});
return view;
}
This all my code what I'm doing in xml and java. But I could not find any error. Any body have a idea what is wrong here? Thanks a lot.
private void navigateToViewDetailProgress(View view) {
RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.relative_layout);
rl.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
(Do your onclick action here)
}
}
}
Call above function in onResume of your Fragment. make sure you pass rootview as a function parameter.
So i have an app with tabbed activity and i want to change the layout of the first tab if the button(btlink) is clicked:
login(1st fragment/tab) code
public class login extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.login, container, false);
final EditText etUtilizador = (EditText) getView().findViewById(R.id.etUtilizador);
final EditText etPassword = (EditText) getView().findViewById(R.id.etPassword);
final Button btLogin = (Button) getView().findViewById(R.id.btLogin);
Button btlink = (Button) getView().findViewById(R.id.btlink);
btlink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent registerIntent;
registerIntent = new Intent(login.this, registar.class);
login.this.startActivity(registerIntent);
}
});
return rootView;
}
}
but it shows an error at:"registerIntent = new Intent(login.this, registar.class);"
login xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin">
</TextView>
<EditText
android:id="#+id/etUtilizador"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/section_label"
android:layout_marginTop="70dp"
android:ems="10"
android:hint="Utilizador"
android:inputType="textPersonName"
android:textColor="#color/colorPrimaryDark" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etUtilizador"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#color/colorPrimaryDark" />
<Button
android:id="#+id/btLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etPassword"
android:layout_marginTop="41dp"
android:background="#color/colorAccent"
android:text="Login"
android:textAppearance="#style/BotaoRegisto" />
<Button
android:id="#+id/btlink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/btLogin"
android:layout_marginTop="49dp"
android:background="#color/colorAccent"
android:text="Registar"
android:textAppearance="#style/BotaoRegisto" />
<TextView
android:id="#+id/tvregisto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/btLogin"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="TextView"
android:textColor="#color/colorPrimary"
tools:text="Se ainda nao tem conta registe-se aqui:" />
I only want the code to change the layout to this when i click on the button:
registar.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin">
</TextView>
<EditText
android:id="#+id/etNome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/section_label"
android:layout_marginTop="70dp"
android:ems="10"
android:hint="Nome"
android:inputType="textPersonName"
android:textColor="#color/colorPrimaryDark" />
<EditText
android:id="#+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etNome"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="#color/colorPrimaryDark" />
<Button
android:id="#+id/btPedido"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etNumero"
android:layout_marginTop="99dp"
android:background="#color/colorAccent"
android:elevation="0dp"
android:text="Enviar pedido de registo"
android:textAppearance="#style/BotaoRegisto" />
<EditText
android:id="#+id/etNumero"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/etEmail"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Nº faturação ou série"
android:inputType="textPersonName"
android:textColor="#color/colorPrimaryDark" />
If someone could i would be thankfull.
At first set rootView instead of getView().
final EditText etUtilizador = (EditText) rootView.findViewById(R.id.etUtilizador);
final EditText etPassword = (EditText) rootView.findViewById(R.id.etPassword);
final Button btLogin = (Button) rootView.findViewById(R.id.btLogin);
Button btlink = (Button) rootView.findViewById(R.id.btlink);
And use getActivity().
Return the Activity this fragment is currently associated with.
new Intent(getActivity(), registar.class);
Code Will
Intent registerIntent;
registerIntent = new Intent(getActivity(), registar.class);
getActivity().startActivity(registerIntent);
change
Intent registerIntent;
registerIntent = new Intent(login.this, registar.class);
login.this.startActivity(registerIntent);
To
Intent registerIntent = new Intent(getActivity(), registar.class);
startActivity(registerIntent);
also need to change
final EditText etUtilizador = (EditText) rootView.findViewById(R.id.etUtilizador);
final EditText etPassword = (EditText) rootView.findViewById(R.id.etPassword);
final Button btLogin = (Button) rootView.findViewById(R.id.btLogin);
public class login extends Fragment{
Context context;
#Override
onAttach(Activity activity){
context=(Context)activity;}
...
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
...
registerIntent = new Intent(context, registar.class);
I have a dialogFragment in my Android application with some views as you can see in the image below:
I am trying to change its size without success, in the Java class I am trying to do this:
getDialog().getWindow().setLayout(800,800);
getDialog().setTitle("Please tell us"); as you can see in the code below:
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateView(LayoutInflaterm ViewGroup, Bundle) - Ini ");
View view = inflater.inflate(R.layout.dialog_box_layout, container, false);
ageSpinner = (Spinner) view.findViewById(R.id.age_spinner_dialog);
ageSpinner.setSelected(false);
ageSpinner.setAdapter(populateAgeSpinner());
ageSpinner.setOnItemSelectedListener(this);
radioDialogMale = (RadioButton) view.findViewById(R.id.radioDialogM);
radioDialogMale.setSelected(false);
radioDialogMale.setOnClickListener(this);
radioDialogFemale = (RadioButton) view.findViewById(R.id.radioDialogF);
radioDialogFemale.setSelected(false);
radioDialogFemale.setOnClickListener(this);
okButton = (Button) view.findViewById(R.id.dialog_ok);
okButton.setOnClickListener(this);
getDialog().getWindow().setLayout(800,800);
getDialog().setTitle("Please tell us");
communicator = (LoginActivity) getActivity();
setCancelable(false);
Log.d(TAG, "onCreateView(LayoutInflaterm ViewGroup, Bundle) - Fi ");
return view;
}
but nothing changes.
here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
<!-- <TextView
android:id="#+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please tell us your age and gender"
android:textSize="22dp"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="#FFF"
android:textStyle="bold"
android:layout_marginBottom="30dp"/> -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="Age"
android:textSize="18dp"
android:gravity="center"/>
<Spinner
android:id="#+id/age_spinner_dialog"
android:layout_width="80dp"
android:spinnerMode="dropdown"
android:layout_height="30dp"
android:layout_marginLeft="18pt"
android:foregroundTint="#color/com_facebook_button_send_background_color"
android:backgroundTint="#FFF"/>
<TextView
android:id="#+id/text_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50pt"
android:text="Gender"
android:textColor="#FFF"
android:textSize="18dp"
android:layout_alignTop="#+id/radioGroup"
android:layout_toEndOf="#+id/age_spinner" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.70"
android:layout_marginEnd="25dp"
android:layout_marginLeft="20dp"
android:id="#+id/radioGroup"
android:layout_alignParentEnd="true">
<RadioButton
android:layout_width="50dp"
android:layout_height="25dp"
android:text="M"
android:layout_marginLeft="12dp"
android:id="#+id/radioDialogM"
android:layout_marginBottom="30dp"
android:textColor="#color/com_facebook_button_send_background_color"
android:backgroundTint="#color/com_facebook_button_send_background_color"
android:buttonTint="#color/com_facebook_button_send_background_color"/>
<RadioButton
android:layout_width="50dp"
android:layout_height="25dp"
android:text="F"
android:id="#+id/radioDialogF"
android:layout_marginRight="5pt"
android:textColor="#color/com_facebook_button_send_background_color"
android:backgroundTint="#color/com_facebook_button_send_background_color"
android:buttonTint="#color/com_facebook_button_send_background_color"/>
</RadioGroup>
/>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="#+id/dialog_ok"
android:background="#color/com_facebook_button_send_background_color"
android:textColor="#FFF"
android:text="OK"
android:layout_below="#+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
help please !!!
You can try to set the width and height for dialog fragment from onResume() method. like below:
public void onResume()
{
super.onResume();
Window window = getDialog().getWindow();
window.setLayout(width, height);
window.setGravity(Gravity.CENTER);
//TODO:
}
THANK YOU FOR ALL OF YOUR HELP!! I NEED TO READ A TUTORIAL. :)
I know it's probably elementary and as you can tell I'm a newbie. I compared my code to others and don't see anything wrong. Thanks! When I click the clear Button after entering data, my edit fields are not cleared.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button clear = (Button)findViewById(R.id.btn_clear);
clear.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
EditText potsize = (EditText) findViewById(R.id.et_pot_size);
EditText tocall = (EditText) findViewById(R.id.et_to_call);
EditText bepercent = (EditText) findViewById(R.id.et_be_per);
potsize.setText("");
tocall.setText("");
bepercent.setText("");
TextView potoddscalc = (TextView)findViewById(R.id.tv_pot_odds_calc);
potoddscalc.setText("5");
}
});
}
XML:
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<requestFocus />
<TextView
android:id="#+id/tv_be_per"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_to_call"
android:layout_below="#+id/tv_to_call"
android:layout_marginTop="34dp"
android:text="#string/BE_Per"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_to_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_pot_size"
android:layout_below="#+id/tv_pot_size"
android:layout_marginTop="33dp"
android:text="#string/to_call"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_pot_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:text="#string/pot_size"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_pot_odds_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/et_be_per"
android:layout_alignTop="#+id/tv_pot_odds"
android:ems="8" />
<EditText
android:id="#+id/et_pot_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv_pot_size"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#+id/tv_pot_odds"
android:ems="10" />
<EditText
android:id="#+id/et_to_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/et_pot_size"
android:layout_alignTop="#+id/tv_to_call"
android:ems="10" />
<EditText
android:id="#+id/et_be_per"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/et_to_call"
android:layout_alignTop="#+id/tv_be_per"
android:ems="10" />
<TextView
android:id="#+id/tv_pot_odds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tv_be_per"
android:layout_below="#+id/et_be_per"
android:layout_marginTop="20dp"
android:text="#string/pot_odds"
android:textStyle="bold" />
<Button
android:id="#+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tv_pot_odds_calc"
android:layout_below="#+id/tv_pot_odds_calc"
android:layout_marginTop="24dp"
android:text="#string/clear_button" />
<Button
android:id="#+id/btn_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btn_clear"
android:layout_alignBottom="#+id/btn_clear"
android:layout_alignLeft="#+id/tv_pot_odds_calc"
android:text="#string/calc_button" />
Try this instead. I believe your problem may be arising from creating new EditTexts and TextView objects every time you click the clear button. In the below code, the EditTexts and TextView are declared only once ,in the OnCreate method. Also, getText().clear() is the "official" way of clearing the text from an EditText (not that it really makes a visual difference).
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button clear = (Button)findViewById(R.id.btn_clear);
EditText potsize = (EditText) findViewById(R.id.et_pot_size);
EditText tocall = (EditText) findViewById(R.id.et_to_call);
EditText bepercent = (EditText) findViewById(R.id.et_be_per);
TextView potoddscalc = (TextView)findViewById(R.id.tv_pot_odds_calc);
clear.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
potsize.getText().clear();
tocall.getText().clear();
bepercent.getText().clear();
potoddscalc.setText("5");
}
});
}
// try this way
<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:padding="5dp"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/tv_pot_size"
android:layout_width="0dp"
android:layout_weight="0.20"
android:gravity="right"
android:layout_height="wrap_content"
android:text="pot_size"
android:textStyle="bold" />
<EditText
android:id="#+id/et_pot_size"
android:layout_width="0dp"
android:layout_weight="0.80"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/tv_to_call"
android:layout_width="0dp"
android:layout_weight="0.20"
android:gravity="right"
android:layout_height="wrap_content"
android:text="to_call"
android:textStyle="bold" />
<EditText
android:id="#+id/et_to_call"
android:layout_width="0dp"
android:layout_weight="0.80"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/tv_be_per"
android:layout_width="0dp"
android:layout_weight="0.20"
android:gravity="right"
android:layout_height="wrap_content"
android:text="BE_Per"
android:textStyle="bold" />
<EditText
android:id="#+id/et_be_per"
android:layout_width="0dp"
android:layout_weight="0.80"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/tv_pot_odds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pot_odds"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_pot_odds_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:ems="8" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center">
<Button
android:id="#+id/btn_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="calc_button" />
<Button
android:id="#+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="clear_button" />
</LinearLayout>
</LinearLayout>
public class MyActivity extends Activity {
private EditText potsize;
private EditText tocall;
private EditText bepercent;
private Button clear;
private Button calc;
private TextView potoddscalc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
clear = (Button)findViewById(R.id.btn_clear);
calc = (Button)findViewById(R.id.btn_calc);
potsize = (EditText) findViewById(R.id.et_pot_size);
tocall = (EditText) findViewById(R.id.et_to_call);
bepercent = (EditText) findViewById(R.id.et_be_per);
potoddscalc = (TextView)findViewById(R.id.tv_pot_odds_calc);
clear.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
clearOrReset();
}
});
}
private void clearOrReset(){
potsize.setText("");
tocall.setText("");
bepercent.setText("");
potoddscalc.setText("5");
}
}
declare all three objects of Edittext in the oncreate method and then try it
enter code here #Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button clear = (Button)findViewById(R.id.btn_clear);
EditText potsize = (EditText) findViewById(R.id.et_pot_size);
EditText tocall = (EditText) findViewById(R.id.et_to_call);
EditText bepercent = (EditText) findViewById(R.id.et_be_per);
TextView potoddscalc = (TextView)findViewById(R.id.tv_pot_odds_calc);
public void onClick(View v)
{
swiech(v.getid())
{
case R.id.btn_clear:
potsize.setText("");
tocall.setText("");
bepercent.setText("");
potoddscalc.setText("5");
}
});
}