I have 2 TextViews showing on the main UI. I associate each TextView to a unique clickListener that launches a unique AlertDialog for the user to make a selection. The first TextView is launching the second layout for the second AlertDialog rather than the expected first layout for the first AlertDialog. What am I missing here?
activity_main.xml file
...
<TextView
android:id="#+id/fList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:text="filter"
android:textStyle="bold|italic"
android:textColor="#color/text_primary"
/>
<TextView
android:id="#+id/qList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="quickList"
android:textStyle="bold"
android:textColor="#color/text_primary"
android:gravity="center"
/>
MainActivity.java file
public class MainActivity extends AppCompatActivity
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView mTextViewFilter = (TextView)findViewById(R.id.fList);
TextView mTextViewQuickList = (TextView)findViewById(R.id.qList);
mTextViewFilter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view){
final AlertDialog.Builder alertDialogFilter = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflaterFilter = getLayoutInflater();
final ViewGroup nullParent = null;
// the AlertDialog layout for the first TextView click.
final View dialogLayoutFilter = inflaterFilter.inflate(R.layout.filter_main, nullParent);
alertDialogFilter.setView(dialogLayoutFilter);
final AlertDialog dialogFilter = alertDialogFilter.show();
...
}
});
mTextViewQuickList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
final ViewGroup nullParent = null;
// the AlertDialog layout for the second TextView click.
final View dialogLayout = inflater.inflate(R.layout.entire_layout, nullParent);
alertDialog.setView(dialogLayout);
final AlertDialog dialog = alertDialog.show();
...
}
});
entire_layout.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="380dp"
android:minHeight="160dp" >
<ImageView
android:id="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingEnd="20dp"
android:contentDescription="x"
android:src="#drawable/ic_close_white_24dp" />
<TextView
android:id="#+id/FullList"
android:layout_below="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Large"
android:text="Show entire list" />
<TextView
android:id="#+id/fullNewest"
android:layout_below="#+id/FullList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="10dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Created ... />
filter_main.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="380dp"
android:minHeight="280dp" >
<ImageView
android:id="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingEnd="20dp"
android:contentDescription="x"
android:src="#drawable/ic_close_white_24dp" />
<TextView
android:id="#+id/Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageViewX"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Large"
android:text="Filter..." />
<TextView
android:id="#+id/AllDos"
android:layout_below="#+id/Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllBuys"
android:layout_below="#+id/AllDos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllWork"
android:layout_below="#+id/AllBuys"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllHome"
android:layout_below="#+id/AllWork"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllWaitingfor"
android:layout_below="#+id/AllHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="5dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
Not sure what your textviews' parent is but since you are using attributes like:
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
I guess it is a RelativeLayout.
Since you aren't using neither an orientation nor a relative position, I suppose your TextViews are both on the same line, with just a different margin top, but the quick list TextView has width match_parent and gravity center
android:layout_width="match_parent"
android:gravity="center"
So what's happening is something like this:
And your click always triggers the second TextView that covers entirely the first one.
To fix it change your quick list TextView this way:
<TextView
android:id="#+id/qList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="quickList"
android:textStyle="bold"
android:textColor="#color/text_primary"
android:layout_centerHorizontal="true"/>
With the attributes:
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
It will be centered but not overlapping the first TextView.
I hope this could help, if instead I am wrong and your activity_main.xml file differs, please update your code so that it can be easier figure out any alternative problem.
Related
enter image description here
In Activty one i have RecyclerView with to View :
HEADER_VIEW
ITEM_VIEW
Header_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFF7F7F7">
<TextView
android:id="#+id/tv_group_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="TextView"
android:textColor="#F50057"
android:textSize="20sp" />
<TextView
android:id="#+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:text="More..." />
</RelativeLayout>
Item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:elevation="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_below="#id/imageView"
android:background="#f5fff2">
<TextView
android:id="#+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="name"
android:textAlignment="center"
android:textColor="#FF20C200"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/new_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/old_price"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:layout_toEndOf="#+id/old_price"
android:text="480.00 DA"
android:textColor="#FF65C2FD"
android:textStyle="bold" />
<TextView
android:id="#+id/old_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv_name"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:text="250.00 DA"
android:textAlignment="center"
android:textColor="#F50057" />
<ImageButton
android:id="#+id/overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/new_price"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:srcCompat="#drawable/ic_more_vert_black_24dp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
I created the Adapter and it Work Fine .
My problem is :
I need when I click on more TextView In HEADER_VIEW an New Activity Start
with Specific Itemes Of Stection.
My try :
In Adapter Exactly in onBindViewHolder
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
//Context context = mContextWeakReference.get();
if (mContext == null) {
return;
}
if (SECTION_VIEW == getItemViewType(position)) {
final SectionViewHolder sectionViewHolder =(SectionViewHolder)holder;
GroupTitleModel sectionItem = ((GroupTitleModel) mUsersAndSectionList.get(position));
sectionViewHolder.title.setText(sectionItem.title);
sectionViewHolder.more.setText(sectionItem.moreSection);
sectionViewHolder.more.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View view) {
// I TRY TO DO IT HERE BUT NO THINGS
}
} );
return;
}
My first thought is that you are bringing yourself into trouble by doing it this way.
You separate the Header view and its Content view, so the problem appear when the Header has no idea which content to continue to next step. If you don't want to refactor than it's ok, there will be a workaround. But my suggestion is that you combine the header and the content into 1 ViewHolder, keep the title, more text, and items inside 1 Model class too. They need to go with each other so they know how to handle with interaction
I have a Tabbed Activity, In Tab2.Java,
I want to show a Custom Dialog on a Button Click. (For Custom Dialog, I have a separate xml file named: dg_selct.xml.)
Code:
public class Tab2 extends Fragment {
Button btn;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab2, container, false);
btn=(Button)v.findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
View bView = getLayoutInflater().inflate(R.layout.dg_selct,null);
dialog.setView(bView);
AlertDialog customDialog = dialog.create();
customDialog.setTitle("Search");
customDialog.show();
}
});
Here is dg_selct.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<CheckBox
android:id="#+id/chkpg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView4"
android:layout_marginStart="63dp"
android:layout_marginTop="27dp"
android:checked="true"
android:text="#string/clspg"
android:textSize="23sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="40dp"
android:layout_marginTop="42dp"
android:text="Mark the Groups, You want to Send the Message:"
android:textColor="#000000"
android:textSize="17sp" />
<CheckBox
android:id="#+id/chknur"
android:checked="true"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chkpg"
android:layout_below="#+id/chkpg"
android:layout_marginTop="32dp"
android:text="#string/clsn" />
<CheckBox
android:id="#+id/chkprep"
android:checked="true"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chknur"
android:layout_below="#+id/chknur"
android:layout_marginTop="30dp"
android:text="#string/clsp" />
<CheckBox
android:id="#+id/chkone"
android:checked="true"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chkprep"
android:layout_below="#+id/chkprep"
android:layout_marginTop="35dp"
android:text="#string/cls1" />
<CheckBox
android:checked="true"
android:id="#+id/chktwo"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chkone"
android:layout_below="#+id/chkone"
android:layout_marginTop="24dp"
android:text="#string/cls2" />
<CheckBox
android:id="#+id/chkthree"
android:checked="true"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chktwo"
android:layout_below="#+id/chktwo"
android:layout_marginTop="26dp"
android:text="#string/cls3" />
<CheckBox
android:id="#+id/chkfour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chkthree"
android:layout_below="#+id/chkthree"
android:checked="true"
android:layout_marginTop="30dp"
android:text="#string/cls4"
android:textSize="23sp" />
<CheckBox
android:id="#+id/chkfive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/chknur"
android:layout_alignEnd="#+id/textView4"
android:layout_marginEnd="32dp"
android:checked="true"
android:text="#string/cls5"
android:textSize="23sp" />
<CheckBox
android:id="#+id/chksix"
android:textSize="23sp"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chkfive"
android:layout_alignTop="#+id/chknur"
android:text="#string/cls6" />
<CheckBox
android:id="#+id/chksvn"
android:checked="true"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chksix"
android:layout_alignTop="#+id/chkprep"
android:text="#string/cls7" />
<CheckBox
android:id="#+id/chknine"
android:textSize="23sp"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chksvn"
android:layout_alignTop="#+id/chkone"
android:text="#string/cls9" />
<CheckBox
android:id="#+id/chkten"
android:textSize="23sp"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chknine"
android:layout_alignTop="#+id/chktwo"
android:text="#string/cls10" />
<CheckBox
android:id="#+id/chkextra"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/chkten"
android:layout_alignTop="#+id/chkthree"
android:text="#string/clsextra"
android:textSize="23sp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
Also, When I use final AlertDialog.Builder dialog = new AlertDialog.Builder(Tab2.this); instead of final AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()); , Compiler gives an error: "Builder (android.Content.context) in Builder cannot be applied to com.abc.Tab2"
dg_select.xml has some CheckBoxes and a TextView. But When Dialog is shown, I only see the title as mentioned in above Code.
How do I inflate the dg_selct.xml in this Dialog?
try this use Dialog instead of AlertDialog
Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.dg_selct);
// to bind your control from dialog like this
final TextView textView= (TextView) dialog.findViewById(R.id.YourTextBiew);
final CheckBox checkBox= (CheckBox) dialog.findViewById(R.id.YourCheckBox);
final Button btnShow = (Button) findViewById(R.id.btnShow);
textView.setText("PREM");
dialog.setTitle("Search");
dialog.show();
UPDATE
change Your RelativeLayout hight & width to match_parent OR wrap_content like below code
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent">
Here ,I saw your xml of dg_select.xml in which you set the height and width of RelativeLayout is 0dp That's why it is unable to show your checkbox. You must have to set RelativeLayout height or width wrap_content or match_parent.
AlertDialog is the part of an Activity that's why it is unable to take reference of fragment.So, You initializing the AlertDialog you must you the Activity reference.
I am developing app having a popup window showing successfully but button inside is not working. When the button is click the event is not listening. The code is shown below.
private void showPopup() {
//LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.popup_layout,null);
mPopupWindow = new PopupWindow(
customView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
Button btn_popup_submit = (Button)customView.findViewById(R.id.btn_popup_submit);
Button btn_popup_cancel = (Button)customView.findViewById(R.id.btn_popup_cancel);
btn_popup_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "aaa", Toast.LENGTH_SHORT).show();
Log.d("LOG","aaaa");
}
});
btn_popup_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "bbbb", Toast.LENGTH_SHORT).show();
Log.d("LOG","bbbb");
}
});
if(Build.VERSION.SDK_INT>=21){
mPopupWindow.setElevation(5.0f);//5.0f
}
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(mContext, android.R.color.transparent)));
mPopupWindow.setOutsideTouchable(false);
mPopupWindow.setTouchable(false);
mPopupWindow.update();
}
The pop up layout code is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_custom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:background="#5b5e93"
>
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Sent."
android:textSize="20sp"
android:textColor="#color/colorWhite"
android:padding="25sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_above="#+id/editText"
android:layout_marginBottom="50dp"
android:background="#color/colorGray"
android:orientation="horizontal"></LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:textSize="16sp"
android:textColor="#color/colorWhite"
android:text="#string/email_sent" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:ems="4"
android:maxLength="4"
android:minLines="4"
android:inputType="number" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/btn_popup_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Submit"
android:textAllCaps="false" />
<Button
android:id="#+id/btn_popup_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/buttoncolor"
android:text="Cancel"
android:textAllCaps="false" />
</LinearLayout>
</RelativeLayout>
The button names are btn_popup_submit and btn_popup_cancel.
I tried different methods but the problem. I don't know where is the problem facing. Please help me thanks.
Replace this line of code.Allow popWindow Touch.
mPopupWindow.setTouchable(false);
to
mPopupWindow.setTouchable(true);
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:
}
I am having real problems trying to set a text to TextView on my android application. The string that I am trying to display was passed to another activity via an intent. I seem to have successfully retrieved this extra from the intent but i am failing to attach it to my TextView. Please can someone help? i am using fragments throughout.
All I am getting is my layout display without the Text that i am trying to assign.
Fragment:2
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.article_fragment, parent, false);
journalTitle = (String) getArguments().getString(EXTRA_JOURNALTITLE); // extra from intent
Log.d("onCreateView", "a.getJournalTitle: " + journalTitle); // this works. displays in logCat
journalTitleView = (TextView) v
.findViewById(R.id.journalTitle_articleFragment_textView);
journalTitleView.setText(journalTitle);
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/journalTitle_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="journal title"
android:textSize="12sp" />
<TextView
android:id="#+id/pubYear_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/journalTitle_articleFragment_textView"
android:text="pubYear"
android:textSize="12sp" />
<TextView
android:id="#+id/volume_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/pubYear_articleFragment_textView"
android:text="volume"
android:textSize="12sp" />
<TextView
android:id="#+id/issue_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/volume_articleFragment_textView"
android:text="issue"
android:textSize="12sp" />
<TextView
android:id="#+id/pageInfo_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/issue_articleFragment_textView"
android:text="pageInfo"
android:textSize="12sp" />
<TextView
android:id="#+id/title_articleFragment_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/journalTitle_articleFragment_textView"
android:gravity="center"
android:layout_marginTop="25dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="article title"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/authorString_articleFragment_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title_articleFragment_textView"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="authors"
android:textSize="12sp" />
<TextView
android:id="#+id/abstractText_articleFragment_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/authorString_articleFragment_textView"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="abstractText"
android:textSize="15sp" />
In onCreateView you should only inflate your layout and return it:
View v = inflater.inflate(R.layout.article_fragment, parent, false);
return v;
Your textView modifications should be moved to onViewCreated
Try :
TextView journalTitleView = (TextView) v.findViewById(R.id.journalTitle_articleFragment_textView);
journalTitleView.setText(journalTitle);
I think you should try this code :
public static void changeFragmentTextView(String s) {
Fragment frag = getFragmentManager().findFragmentById(R.id.yourFragment);
((TextView) frag.getView().findViewById(R.id.ournalTitle_articleFragment_textView)).setText(s);
}`