Rotate TextView DrawableRight OnClick - java

I have a TextView with an arrow set on the right of it. I want the arrow to rotate when it is clicked and return it back to the previous position when it is clicked again to show and hide text. I have been able to show and hide the information I just can't get the rotation animation to work.
XML
<TextView
android:id="#+id/expandable_first_next_last_air_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:drawableEnd="#drawable/ic_keyboard_arrow_down_white_24dp"
android:drawableTint="?attr/textColor"
android:text="First, Next & Last Air Date"
android:textColor="?attr/textColor"
android:textSize="26sp" />
TextView OnClick Listener
tvExpandableFirstNextLastAirDate = findViewById(R.id.expandable_first_next_last_air_date);
tvExpandableFirstNextLastAirDate.setOnClickListener(v -> {
if (isTextViewClicked){
tvFirstNextLastAirDate.setMaxLines(0);
isTextViewClicked = false;
}
else{
tvFirstNextLastAirDate.setMaxLines(Integer.MAX_VALUE);
isTextViewClicked = true;
}
});

java:
final TextView textView = findViewById(R.id.text_view);
final ImageView imageView = findViewById(R.id.image_view);
final TextView textView2 = findViewById(R.id.text_view2);
final ImageView imageView2 = findViewById(R.id.image_view2);
final AnimationSet animSetUp = new AnimationSet(true);
animSetUp.setInterpolator(new DecelerateInterpolator());
animSetUp.setFillAfter(true);
animSetUp.setFillEnabled(true);
final AnimationSet animSetDown = new AnimationSet(true);
animSetDown.setInterpolator(new DecelerateInterpolator());
animSetDown.setFillAfter(true);
animSetDown.setFillEnabled(true);
final RotateAnimation animRotateUp = new RotateAnimation(0.0f, 180.0f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
animRotateUp.setDuration(1500);
animRotateUp.setFillAfter(true);
animSetUp.addAnimation(animRotateUp);
final RotateAnimation animRotateDown = new RotateAnimation(180.0f, 0.0f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
animRotateDown.setDuration(1500);
animRotateDown.setFillAfter(true);
animSetDown.addAnimation(animRotateDown);
final boolean[] isTextViewClickedForTextView1 = {true};
final boolean[] isTextViewClickedForTextView2 = {true};
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (isTextViewClickedForTextView1[0]) {
textView.setMaxLines(0);
isTextViewClickedForTextView1[0] = false;
imageView.startAnimation(animSetUp);
} else {
imageView.startAnimation(animSetDown);
textView.setMaxLines(Integer.MAX_VALUE);
isTextViewClickedForTextView1[0] = true;
}
}
});
textView2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (isTextViewClickedForTextView2[0]) {
textView2.setMaxLines(0);
isTextViewClickedForTextView2[0] = false;
imageView2.startAnimation(animSetUp);
} else {
imageView2.startAnimation(animSetDown);
textView2.setMaxLines(Integer.MAX_VALUE);
isTextViewClickedForTextView2[0] = true;
}
}
});
XML :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="10dp"
android:padding="10dp"
android:text="text view 1"
android:textAlignment="viewStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:padding="5dp"
android:src="#drawable/ic_baseline_arrow_drop_down_24"
app:layout_constraintBottom_toBottomOf="#+id/text_view"
app:layout_constraintEnd_toEndOf="#+id/text_view"
app:layout_constraintTop_toTopOf="#+id/text_view" />
<TextView
android:id="#+id/text_view2"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_margin="10dp"
android:padding="10dp"
android:text="text view 2"
android:textAlignment="viewStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_view"/>
<ImageView
android:id="#+id/image_view2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:padding="5dp"
android:src="#drawable/ic_baseline_arrow_drop_down_24"
app:layout_constraintBottom_toBottomOf="#+id/text_view2"
app:layout_constraintEnd_toEndOf="#+id/text_view2"
app:layout_constraintTop_toTopOf="#+id/text_view2" />
</androidx.constraintlayout.widget.ConstraintLayout>
res/anim/ic_baseline_arrow_drop_down_24.xml :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/cycle_interpolator">
<rotate android:fromDegrees="0"
android:toDegrees="180"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000" />
</set>

Related

Show entire Bottom sheet with toolbar when keyboard is visible

in my application i have 'bottom sheet dialog fragment' when i open it, it work fine, like below image:
but when keyboard is visible the upper toolbar disappear, like below image show.
My Question is how to make toolbar always visible even when keybord is visible....
Here is my '"sheet bottom xml"'
<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:id="#+id/lyt_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="#color/grey_5"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageButton
android:id="#+id/bt_close"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
app:srcCompat="#drawable/ic_close"
app:tint="#color/grey_80" />
<ImageButton
android:id="#+id/save"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
app:srcCompat="#drawable/ic_bookmark_border"
app:tint="#color/grey_80" />
<ImageButton
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
app:srcCompat="#drawable/ic_repeat"
app:tint="#color/grey_80" />
<ImageButton
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
app:srcCompat="#drawable/ic_more_vert"
app:tint="#color/grey_80" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/app_bar_layout2"
android:layout_below="#+id/app_bar_layout"
android:clipToPadding="false"
android:fillViewport="true"
android:scrollbars="none"
android:scrollingCache="true"
app:layout_behavior=
"#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical"
android:padding="#dimen/spacing_large">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/bottom_sheet_recycler_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:itemCount="10" />
<LinearLayout
android:id="#+id/lyt_spacer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="No comments yet"
android:textSize="22dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="#+id/app_bar_layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:clipToPadding="false"
android:paddingBottom="10dp"
android:scrollbars="none"
android:scrollingCache="true"
app:layout_anchorGravity="bottom|center">
<EditText
android:id="#+id/post_view_enter_comment_edit_Text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="4dp"
android:layout_marginEnd="5dp"
android:layout_weight="1"
android:background="#drawable/edit_text_round_bg"
android:hint="Write comment..."
android:lineSpacingExtra="2dp"
android:maxLength="400"
android:maxLines="5"
android:textColor="#color/black"
android:textSize="17sp"/>
<ImageView
android:id="#+id/post_view_send_comment"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginVertical="5dp"
android:layout_marginEnd="10dp"
android:background="#drawable/shape_circle"
android:backgroundTint="#color/blue_grey_300"
android:clickable="true"
android:padding="4dp"
android:paddingStart="6dp"
android:src="#android:drawable/ic_menu_send" />
</LinearLayout>
</RelativeLayout>
And also here my "BottomFragment.java".
public class FragmentBottomSheetDialogFull extends
BottomSheetDialogFragment {
private BottomSheetBehavior mBehavior;
private AppBarLayout app_bar_layout;
private RelativeLayout parent_lyt;
private RecyclerView recyclerView;
TopicRecyclerAdapter adapter;
ArrayList<String> topicsArrayList, selectedArray;
ConstraintLayout sheet_constraint_layout;
private String Post_id;
private String content;
private String topic;
public void setData(String post_id, String post_content,
String topic) {
this.Post_id = post_id;
this.content = post_content;
this.topic = topic;
}
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final BottomSheetDialog dialog = (BottomSheetDialog)
super.onCreateDialog(savedInstanceState);
final View view = View.inflate(getContext(),
R.layout.fragment_bottom_sheet_dialog_full, null);
setStyle(DialogFragment.STYLE_NORMAL,
R.style.DialogStyle);
dialog.setContentView(view);
mBehavior = BottomSheetBehavior.from((View)
view.getParent());
mBehavior.setPeekHeight(BottomSheetBehavior.PEEK_HEIGHT_AUTO);
app_bar_layout = (AppBarLayout)
view.findViewById(R.id.app_bar_layout);
parent_lyt = (RelativeLayout)
view.findViewById(R.id.lyt_parent);
mBehavior.setMaxHeight((Tools.getScreenHeight() / 2) +
100);
recyclerView =
view.findViewById(R.id.bottom_sheet_recycler_comment);
topicsArrayList = new ArrayList<>();
selectedArray = new ArrayList<>();
for (int i = 0; i < 50; i++) {
topicsArrayList.add("my " + i);
}
adapter = new TopicRecyclerAdapter(topicsArrayList,
selectedArray);
recyclerView.setLayoutManager(new
LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
mBehavior.setBottomSheetCallback(new
BottomSheetBehavior.BottomSheetCallback() {
#Override
public void onStateChanged(#NonNull View
bottomSheet, int newState) {
if (BottomSheetBehavior.STATE_HIDDEN ==
newState) {
dismiss();
}
}
#Override
public void onSlide(#NonNull View bottomSheet,
float slideOffset) {
}
});
((ImageButton)
view.findViewById(R.id.bt_close)).setOnClickListener(new
View.OnClickListener() {
#Override
public void onClick(View v) {
dismiss();
}
});
return dialog;
}
#Override
public void onStart() {
super.onStart();
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
private void hideView(View view) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = 0;
view.setLayoutParams(params);
// dismiss();
// dismissAllowingStateLoss();
}
private void showView(View view, int size) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = size;
view.setLayoutParams(params);
}
private int getActionBarSize() {
final TypedArray styledAttributes =
getContext().getTheme().obtainStyledAttributes(new int[]
{android.R.attr.actionBarSize});
int size = (int) styledAttributes.getDimension(0, 0);
return size;
}
}
What exactly i seek to achieve is shown in this image, the toolbar is stable despite keyboard is visible or not.
Thanks for any help
You can try this to initialize your activity in manifest.
<activity
android:name=".Activities"
android:configChanges="orientation|screenSize|layoutDirection"
android:exported="true"
android:screenOrientation="portrait"android:windowSoftInputMode="adjustPan|adjustResize|stateAlwaysVisible"/>
The most convenient way that I found to change this is by creating style:
<style name="DialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
And set this in onCreate method of your BottomSheetDialogFragment:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle)}
Hope this will help you.
The best way to do that is to make specific style for that inside styles.xml
<style name="DialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize|stateAlwaysVisible</item>
Once we can't initialize any fragment or BottomSheetDialogFragment inside our manifest, the best way is to go to styles.xml (DialogStyle) and and make
<item name="android:windowsSoftInputMode">adjustResize|stateAlwaysVisible</item>
After that we should override onCreate inside our FragmentBottomSheetDialog.java
override void onCreate(#Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle);
}
this works prefectly
Thanks for #hardik-kotadiya

How to save the data from multiple Edittexts that are being added dynamically in android?

I have some EditTexts and I'm trying to save their values to an ArrayList, but my EditTexts are being added by using an add button which adds a LinearLayout, and the EditTexts are within the LinearLayouts being created.
Normally having a fixed amount of EditTexts would be easy to save, but how would I save a continuous amount of EditTexts. I'm adding the LinearLayouts in the method createNewLinearLayout() below, and I want to save the input from the EditTexts from those LinearLayouts.
How can I do that?
My layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:id="#+id/relativeOverall"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:id="#+id/relativeLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/addCounter"
android:text="Add"
android:layout_marginLeft="0dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/saveBtn"
android:layout_toRightOf="#+id/addCounter"
android:text="Save Data"
android:layout_marginLeft="30dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnView"
android:text="View Data"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/saveBtn" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/horizontalLine"
android:background="#B3B3B3"
android:layout_below="#+id/relativeLayout"
android:layout_marginTop="10dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/nameEditText"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:hint="Name of Patient"
android:layout_below="#+id/horizontalLine"/>
<View
android:layout_width="match_parent"
android:layout_height="1sp"
android:id="#+id/horizontalLine2"
android:background="#B3B3B3"
android:layout_below="#+id/nameEditText"
android:layout_marginTop="0dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/idEditText"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:hint="ID of Patient"
android:layout_below="#+id/horizontalLine2"/>
<View
android:layout_width="match_parent"
android:layout_height="1sp"
android:id="#+id/horizontalLine3"
android:background="#B3B3B3"
android:layout_below="#+id/idEditText"
android:layout_marginTop="0dp"/>
<EditText
android:layout_width="245dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="#+id/actionEditText"
android:textAlignment="center"
android:hint="Action To Record"
android:layout_below="#+id/horizontalLine3"/>
<EditText
android:layout_width="245dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="#+id/durationEditText"
android:textAlignment="center"
android:hint="Duration of Action"
android:layout_below="#+id/actionEditText"/>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_below="#+id/durationEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:layout_marginTop="0dp">
<Button
android:id="#+id/minusBtn"
android:layout_width="55sp"
android:layout_height="55sp"
android:text="-"
android:textSize="25dp"/>
<TextView
android:id="#+id/counterTxt"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:textSize="45sp"
android:text="25"/>
<Button
android:id="#+id/plusBtn"
android:layout_width="55sp"
android:layout_height="55sp"
android:text="+"
android:textSize="25sp"/>
</LinearLayout>
<Button
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/delete"
android:layout_below="#+id/linearLayout"
android:text="Delete"
android:textAlignment="center"
android:layout_centerHorizontal="true"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:id="#+id/linearLayoutText"
android:layout_below="#+id/horizontalLine3">
</LinearLayout>
</RelativeLayout>
</ScrollView>
My method
private LinearLayout createNewLinearLayout(){
final LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lparams.gravity = Gravity.CENTER_HORIZONTAL;
final ViewGroup.LayoutParams btnParam = plusBtn.getLayoutParams();
final ViewGroup.LayoutParams textParam = counterTxt.getLayoutParams();
final LinearLayout.LayoutParams deleteParam = new LinearLayout.LayoutParams(delete.getLayoutParams());
deleteParam.gravity = Gravity.CENTER_HORIZONTAL;
final LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(actionEditText.getLayoutParams());
editParams.gravity = Gravity.CENTER_HORIZONTAL;
final LinearLayout.LayoutParams durationParams = new LinearLayout.LayoutParams(durationEditText.getLayoutParams());
durationParams.gravity = Gravity.CENTER_HORIZONTAL;
LinearLayout.LayoutParams line = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,TypedValue.COMPLEX_UNIT_SP, 1);
line.setMargins(0,15,0,0);
final LinearLayout newLinear = new LinearLayout(this);
newLinear.setLayoutParams(lparams);
final LinearLayout combined = new LinearLayout(this);
combined.setLayoutParams(lparams);
final Button plus = new Button(this);
plus.setLayoutParams(btnParam);
final Button minus = new Button(this);
minus.setLayoutParams(btnParam);
final TextView count = new TextView(this);
count.setLayoutParams(textParam);
final EditText editText = new EditText(this);
editText.setLayoutParams(editParams);
editText.setHint("Action To Record");
editText.setGravity(Gravity.CENTER_HORIZONTAL);
final View v = new View(this);
v.setLayoutParams(line);
v.setBackgroundColor(Color.parseColor("#B3B3B3"));
final EditText duration = new EditText(this);
duration.setLayoutParams(durationParams);
duration.setHint("Duration of Action");
duration.setGravity(Gravity.CENTER_HORIZONTAL);
final Button delete = new Button(this);
delete.setLayoutParams(deleteParam);
delete.setText("delete");
delete.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v) {
linearLayoutText.removeView(combined);
}
});
plus.setText("+");
plus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
plus.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v) {
counting[0]++;
count.setText(counting[0] + "");
}
});
minus.setText("-");
minus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
minus.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v) {
if (counting[0] > 0)
counting[0]--;
count.setText(counting[0] + "");
}
});
count.setTextSize(TypedValue.COMPLEX_UNIT_SP, 45);
newLinear.setOrientation(LinearLayout.HORIZONTAL);
newLinear.setGravity(Gravity.CENTER_HORIZONTAL);
combined.setOrientation(LinearLayout.VERTICAL);
combined.setGravity(Gravity.CENTER_HORIZONTAL);
newLinear.addView(minus);
newLinear.addView(count);
newLinear.addView(plus);
combined.addView(editText);
combined.addView(duration);
combined.addView(newLinear);
combined.addView(delete);
combined.addView(v);
counting[0] = 0;
count.setText(counting[0] + "");
return combined;
}
}
I suggest :
for (int i =0;i<LinearLayout.getChildCount();i++)
{
EditText edt= new EditText (this);
edt = LinearLayout.getChildAt(i);
YourAarraylist[i]=edt.getText().toString();
}
If you have multiple views inside your LinearLayout you can repeat the for like this :
for (int i =0;i<LinearLayout.getChildCount();i++)
{
LinearLayout secondLayout= (LinearLayout) LinearLayout.getChildAt(i);
// and then:
EditText edt= new EditText (this);
edt = secondLayout.getChildAt(indexofyoutEdittext);//You should know this because it's the order of the views you add in your layout
YourAarraylist[i]=edt.getText().toString();
}
I hope it helps !

second activity crashes only on the phone not on the emulator

The first screen upload right and works fine (Toast and all other setting and parameters) until I try to save the result and open the new screen by the same button. Pushing the button crashes the app in my phone without opening the second screen. However in the emulator all work fine.
this is the Main activity:
public class MainActivity extends AppCompatActivity {
LineChart lineChart1;
RadioGroup rg1,rg2;
Button tipBtn;
Button checkAndCont;
int [] mSlop ={-1,3};
int [] b= {-3,3};
boolean userAnswer1 = false;
boolean userAnswer2 = false;
String quesType = "Slop Recognition";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lineChart1 = (LineChart)findViewById(R.id.lineChart1);
rg1 = (RadioGroup)findViewById(R.id.rg1);
rg2 = (RadioGroup)findViewById(R.id.rg2);
tipBtn = (Button)findViewById(R.id.tipBtb);
tipBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"גרף במערכת צירים נקרא משמאל לימין",Toast.LENGTH_SHORT ).show();
}
});
checkAndCont = (Button)findViewById(R.id.checkAndCont);
ArrayList<String> xAxes = new ArrayList<>();
ArrayList<Entry> yAxesLinear1 = new ArrayList<>();
ArrayList<Entry> yAxesLinear2 = new ArrayList<>();
int numberDataPoint = 21;
for (int i=0 ; i<numberDataPoint;i++ ){
int x=i-10;
float funLinear1= mSlop[0]*x+b[0];
float funLinear2= mSlop[1]*x+b[1];
yAxesLinear1.add(new Entry(x,funLinear1));
yAxesLinear2.add(new Entry(x,funLinear2));
//xAxes.add(i,String.valueOf(x));
}
//String [] xaxes = new String[xAxes.size()];
//for (int i=0; i<xAxes.size(); i++){
// xaxes[i]=xAxes.get(i);
//}
ArrayList<ILineDataSet> lineDataSet= new ArrayList<>();
LineDataSet lineDataSet1 = new LineDataSet(yAxesLinear1,"פונקציה קווית 1");
lineDataSet1.setDrawCircles(false);
lineDataSet1.setColor(Color.CYAN);
lineDataSet1.setDrawValues(false);
lineDataSet1.setLineWidth(3);
LineDataSet lineDataSet2 = new LineDataSet(yAxesLinear2,"פונקציה קווית 2");
lineDataSet2.setDrawCircles(false);
lineDataSet2.setColor(Color.GREEN);
lineDataSet2.setDrawValues(false);
lineDataSet2.setLineWidth(3);
lineDataSet.add(lineDataSet1);
lineDataSet.add(lineDataSet2);
lineChart1.setData(new LineData(lineDataSet));
lineChart1.setDrawBorders(true);
lineChart1.setBorderColor(0xffff00ff);
lineChart1.setBorderWidth(2);
lineChart1.setScaleEnabled(true);
//lineChart1.setDrawGridBackground(true);
//lineChart1.setGridBackgroundColor(0xffff00ff);
//lineChart1.setBackgroundColor(0x00000000);
XAxis xAxis = lineChart1.getXAxis();
//xAxis.setEnabled(true);
xAxis.setDrawAxisLine(true);
xAxis.setAxisLineColor(Color.WHITE);
lineChart1.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
lineChart1.getAxisRight().setEnabled(false);
lineChart1.getXAxis().setAxisMaximum(10);
lineChart1.getXAxis().setAxisMinimum(-10);
lineChart1.getXAxis().setGridColor(0xffff00ff);
//lineChart1.getXAxis().setDrawAxisLine(true);
//lineChart1.getXAxis().setAxisLineColor(Color.WHITE); // The buttom limit line of the chart
//lineChart1.setVisibleXRangeMaximum(50);
lineChart1.getXAxis().setTextColor(Color.WHITE);
lineChart1.getXAxis().setTextSize(15);
LimitLine ll = new LimitLine(0);
ll.setLineColor(Color.WHITE);
ll.setLineWidth(1);
xAxis.addLimitLine(ll);
YAxis yAxis = lineChart1.getAxisLeft();
yAxis.setDrawZeroLine(true);
yAxis.setZeroLineColor(Color.WHITE);// no grid lines
yAxis.setZeroLineWidth(1); //Sets the line-width of the zero line.
yAxis.setAxisMinimum(-10f); // start at zero
yAxis.setAxisMaximum(10f); // the axis maximum is 100
yAxis.setGridColor(0xffff00ff);
yAxis.setTextColor(Color.WHITE);
yAxis.setTextSize(15);
Legend legend = lineChart1.getLegend();
legend.setEnabled(true);
legend.setTextColor(Color.WHITE);
legend.setTextSize(18);
legend.setFormSize(13);
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
RadioButton rb1 = (RadioButton) radioGroup.findViewById(i);
//if(R.id.rg1==i ? userAnswer1==true : userAnswer1==false);
if (null != rb1 && i > -1) {
// checkedId is the RadioButton selected
switch (i) {
case R.id.rb1:
userAnswer1=false;
break;
case R.id.rb2:
userAnswer1=true;
break;
}
}
Toast.makeText(MainActivity.this,Boolean.toString(userAnswer1),Toast.LENGTH_SHORT ).show();
}
});
rg2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
RadioButton rb2 = (RadioButton) radioGroup.findViewById(i);
//if(R.id.rg1==i ? userAnswer1==true : userAnswer1==false);
if (null != rb2 && i > -1) {
// checkedId is the RadioButton selected
switch (i) {
case R.id.rb3:
userAnswer2=false;
break;
case R.id.rb4:
userAnswer2=true;
break;
}
}
Toast.makeText(MainActivity.this,Boolean.toString(userAnswer2),Toast.LENGTH_SHORT ).show();
}
});
}
public void result(View view) {
if (isTrue(mSlop[0])==userAnswer1 && isTrue(mSlop[1])==userAnswer2){
Toast.makeText(MainActivity.this,"תשובה נכונה",Toast.LENGTH_SHORT ).show();
}else {
Toast.makeText(MainActivity.this,"לא נכון",Toast.LENGTH_SHORT ).show();
}
startActivity(new Intent(MainActivity.this, Main2Activity.class));
}
boolean mType;
public boolean isTrue (int m){
if (m >0){
mType=true;
}else{
mType=false;
}
return mType;
}
}
this is the related XML:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:background="#drawable/background_color">
<com.github.mikephil.charting.charts.LineChart
android:layout_width="match_parent"
android:layout_height="400dp"
android:id="#+id/lineChart1">
</com.github.mikephil.charting.charts.LineChart>
<TextView
android:id="#+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/lineChart1"
android:layout_marginStart="187dp"
android:paddingRight="15dp"
android:text="פונקציה 1 עולה"
android:textColor="#00FFFF"
android:textSize="25sp" />
<TextView
android:id="#+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv1"
android:layout_marginStart="187dp"
android:paddingRight="15dp"
android:text="פונקציה 2 עולה"
android:textColor="#ff00ff00"
android:textSize="25sp" />
<RadioGroup
android:id="#+id/rg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/lineChart1"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#00FFFF"
android:text="לא נכון"
android:textColor="#00FFFF"
android:paddingLeft="2dp"
android:textSize="25sp"
/>
<RadioButton
android:id="#+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#00FFFF"
android:text="נכון"
android:textColor="#00FFFF"
android:paddingLeft="2dp"
android:textSize="25sp"
android:layout_marginLeft="5sp"/>
</RadioGroup>
<RadioGroup
android:id="#+id/rg2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/rg1"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#ff00ff00"
android:text="לא נכון"
android:textColor="#ff00ff00"
android:paddingLeft="2dp"
android:textSize="25sp"
/>
<RadioButton
android:id="#+id/rb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#ff00ff00"
android:text="נכון"
android:textColor="#ff00ff00"
android:paddingLeft="2dp"
android:textSize="25sp"
android:layout_marginLeft="5dp"/>
</RadioGroup>
<Button
android:id="#+id/tipBtb"
android:layout_width="50sp"
android:layout_height="50sp"
android:layout_alignParentStart="true"
android:layout_below="#+id/rg2"
android:layout_marginStart="66dp"
android:layout_marginTop="11dp"
android:scaleType="fitCenter"
android:text="TIP" />
<Button
android:id="#+id/checkAndCont"
android:text="שלח"
android:layout_width="80sp"
android:layout_height="50sp"
android:layout_marginTop="11dp"
android:layout_below="#+id/tv2"
android:layout_centerHorizontal="true"
android:onClick="result"/>
</RelativeLayout>
this is the second activity:
public class Main2Activity extends AppCompatActivity {
LineChart lineChart2;
Button quickTipBtn,sendAndNext;
TextView question1,question2;
EditText answer1,answer2;
final int [] mSlop ={1,3};
final int [] b= {1,3};
private boolean userAnswer1 = false;
private boolean userAnswer2 = false;
final String quesType = "y-intercept Recognition";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
question1 = (TextView)findViewById(R.id.question1);
question2 = (TextView)findViewById(R.id.question2);
answer1 = (EditText)findViewById(R.id.answer1);
answer2 = (EditText)findViewById(R.id.answer2);
quickTipBtn =(Button)findViewById(R.id.quickTipBtn);
quickTipBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(Main2Activity.this,"קואורדינטת החיתוך עם ציר Y ו b - שווים",Toast.LENGTH_SHORT ).show();
}
});
sendAndNext = (Button)findViewById(R.id.sendAndNext);
lineChart2 = (LineChart)findViewById(R.id.lineChart2);
ArrayList<String> xAxes = new ArrayList<>();
ArrayList<Entry> yAxesLinear1 = new ArrayList<>();
ArrayList<Entry> yAxesLinear2 = new ArrayList<>();
int numberDataPoint = 21;
for (int i=0 ; i<numberDataPoint;i++ ){
int x=i-10;
float funLinear1= mSlop[0]*x+b[0];
float funLinear2= mSlop[1]*x+b[1];
yAxesLinear1.add(new Entry(x,funLinear1));
yAxesLinear2.add(new Entry(x,funLinear2));
//xAxes.add(i,String.valueOf(x));
}
//String [] xaxes = new String[xAxes.size()];
//for (int i=0; i<xAxes.size(); i++){
// xaxes[i]=xAxes.get(i);
//}
ArrayList<ILineDataSet> lineDataSet= new ArrayList<>();
LineDataSet lineDataSet1 = new LineDataSet(yAxesLinear1,"פונקציה קווית 1");
lineDataSet1.setDrawCircles(false);
lineDataSet1.setColor(Color.CYAN);
lineDataSet1.setDrawValues(false);
lineDataSet1.setLineWidth(3);
LineDataSet lineDataSet2 = new LineDataSet(yAxesLinear2,"פונקציה קווית 2");
lineDataSet2.setDrawCircles(false);
lineDataSet2.setColor(Color.GREEN);
lineDataSet2.setDrawValues(false);
lineDataSet2.setLineWidth(3);
lineDataSet.add(lineDataSet1);
lineDataSet.add(lineDataSet2);
lineChart2.setData(new LineData(lineDataSet));
lineChart2.setDrawBorders(true);
lineChart2.setBorderColor(0xffff00ff);
lineChart2.setBorderWidth(2);
lineChart2.setScaleEnabled(true);
//lineChart1.setDrawGridBackground(true);
//lineChart1.setGridBackgroundColor(0xffff00ff);
//lineChart1.setBackgroundColor(0x00000000);
XAxis xAxis = lineChart2.getXAxis();
//xAxis.setEnabled(true);
xAxis.setDrawAxisLine(true);
xAxis.setAxisLineColor(Color.WHITE);
lineChart2.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
lineChart2.getAxisRight().setEnabled(false);
lineChart2.getXAxis().setAxisMaximum(10);
lineChart2.getXAxis().setAxisMinimum(-10);
lineChart2.getXAxis().setGridColor(0xffff00ff);
//lineChart1.getXAxis().setDrawAxisLine(true);
//lineChart1.getXAxis().setAxisLineColor(Color.WHITE); // The buttom limit line of the chart
//lineChart1.setVisibleXRangeMaximum(50);
lineChart2.getXAxis().setTextColor(Color.WHITE);
lineChart2.getXAxis().setTextSize(15);
LimitLine ll = new LimitLine(0);
ll.setLineColor(Color.WHITE);
ll.setLineWidth(1);
xAxis.addLimitLine(ll);
YAxis yAxis = lineChart2.getAxisLeft();
yAxis.setDrawZeroLine(true);
yAxis.setZeroLineColor(Color.WHITE);// no grid lines
yAxis.setZeroLineWidth(1); //Sets the line-width of the zero line.
yAxis.setAxisMinimum(-10f); // start at zero
yAxis.setAxisMaximum(10f); // the axis maximum is 100
yAxis.setGridColor(0xffff00ff);
yAxis.setTextColor(Color.WHITE);
yAxis.setTextSize(15);
Legend legend = lineChart2.getLegend();
legend.setEnabled(true);
legend.setTextColor(Color.WHITE);
legend.setTextSize(18);
legend.setFormSize(13);
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
}
public void sendAndNext(View view) {
String temValue1= answer1.getText().toString();
//Toast.makeText(secondScreen.this, answer1.getText(),Toast.LENGTH_LONG).show();
String temValue2= answer2.getText().toString();
if (Integer.parseInt(temValue1)==mSlop[0] && Integer.parseInt(temValue2)==mSlop[1]){
Toast.makeText(Main2Activity.this, "תשובה נכונה",Toast.LENGTH_LONG).show();
}else {
Toast.makeText(Main2Activity.this, "תשובה לא נכונה או שלא הוזנו נתונים",Toast.LENGTH_LONG).show();
}
}
}
this is the second XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
android:gravity="top"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:background="#drawable/background_color2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp">
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/lineChart2"
android:layout_width="match_parent"
android:layout_height="400dp"
>
</com.github.mikephil.charting.charts.LineChart>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:gravity="right">
<EditText
android:id="#+id/answer1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:digits="0123456789."
android:inputType="numberSigned"
android:maxLength="2"
android:hint="הכנס מספר"
android:textColorHint="#78ffd6"
android:textSize="18dp"
android:textColor="#00FFFF"
/>
<TextView
android:id="#+id/question1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:text="למה שווה הפרמטר b ?"
android:textColor="#00FFFF"
android:textSize="25sp"
>
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:gravity="right"
>
<EditText
android:id="#+id/answer2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:digits="0123456789."
android:maxLength="2"
android:hint="הכנס מספר"
android:textColorHint="#64f38c"
android:textSize="18dp"
android:inputType="numberSigned"
android:textColor="#ff00ff00"
/>
<TextView
android:id="#+id/question2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:text="מהי נק' החיתוך עם ציר Y?"
android:textColor="#ff00ff00"
android:textSize="25sp"
>
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:orientation="horizontal"
android:weightSum="2"
android:gravity="center">
<Button
android:layout_marginRight="40dp"
android:id="#+id/quickTipBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Quick Tip"
android:background="#android:color/transparent"
android:textColor="#f05053"
/>
<Button
android:id="#+id/sendAndNext"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Next One"
android:background="#android:color/transparent"
android:textColor="#ffafbd"
android:onClick="sendAndNext"/>
</LinearLayout>
</LinearLayout>
this is the Logcat error:
FATAL EXCEPTION: main
Process: com.example.rachmani.mythematix_linears, PID: 18087
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.rachmani.mythematix_linears/com.example.rachmani.mythematix_linears.Main2Activity}:
android.view.InflateException: Binary XML file line #0: Error
inflating class
Thanks for your patience...
After a close review of the error log, I've indicated the next error:
com.example.rachmani.mythematix_linears:drawable/background_color2" (7f060055) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060055 a=-1 r=0x7f060055}
The original drawable was:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#0f0c29"
android:endColor="#302b63"
android:type="linear"
android:angle="90"/>
</shape>
</item>
</selector>
Just changed it to:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#141e30"
android:endColor="#243b55"
android:type="linear"
android:angle="90"/>
</shape>
</item>
</selector>
It's seems that the gradient background I tried to use make the problem...
Thanks all for your support.
Please check your second XML file for a closing </LinearLayout> tag in the end.
From the code snippet you have posted,it is evident that you haven't closed the first LinearLayout tag. Hope it helps!

Scroll entire page when particular EditText has focus?

I have registration page,in that four EditText exists,when I click on third EditText one LinearLayout(assume password guidelines) has to be visible and at the same time total layout should be scroll to view all guidelines.When other EditText (1,2 or 4) got focus this LinearLayout(password guidelines) should be closed. I tried lot and I searched lot , no solution worked for me,please help me. For understand I did small project ,please watch it.
public class MainActivity extends AppCompatActivity {
private EditText mEditText1,mEditText2,mEditText3,mEditText4;
private LinearLayout ll,root;
ScrollView mScrollView ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
root = (LinearLayout) findViewById(R.id.ll_linear_layout);
ll = (LinearLayout) findViewById(R.id.ll);
mEditText1 = (EditText) findViewById(R.id.et1);
mEditText2 = (EditText) findViewById(R.id.et2);
mEditText3 = (EditText) findViewById(R.id.et3);
mEditText4 = (EditText) findViewById(R.id.et4);
mEditText1.setOnFocusChangeListener(mListener1);
mEditText2.setOnFocusChangeListener(mListener2);
mEditText3.setOnFocusChangeListener(mLayoutExtract);
mEditText4.setOnFocusChangeListener(mListener4);
mScrollView = new ScrollView(this);
}
View.OnFocusChangeListener mListener1 = new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if (b) {
} else {
}
}
};
View.OnFocusChangeListener mListener2 = new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if (b) {
} else {
}
}
};
View.OnFocusChangeListener mLayoutExtract = new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if (b) {
ll.setVisibility(View.VISIBLE);
} else {
ll.setVisibility(View.GONE);
}
}
};
View.OnFocusChangeListener mListener4 = new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if (b) {
} else {
}
}
}};
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/ll_linear_layout"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:layout_marginTop="200dp"
android:id="#+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="first name"/>
<EditText
android:id="#+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<EditText
android:id="#+id/et3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<LinearLayout
android:id="#+id/ll"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="75dp"
android:textColor="#000000"
android:text="Hidable text"/>
</LinearLayout>
<EditText
android:id="#+id/et4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
Try this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/ll_linear_layout"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:layout_marginTop="200dp"
android:id="#+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="first name"/>
<EditText
android:id="#+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<EditText
android:id="#+id/et3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
<LinearLayout
android:id="#+id/ll"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="75dp"
android:textColor="#000000"
android:text="Hidable text"/>
</LinearLayout>
<EditText
android:id="#+id/et4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="second name"/>
</LinearLayout>
</ScrollView>
Try this use android:windowSoftInputMode="AdjustResize" in Your Manifest where your are decraing YOur Activity like below code
<activity
android:name=".YourActivity"
android:parentActivityName="XXX.XXX.XXXX"
android:windowSoftInputMode="AdjustResize" />

How to hide Linear Layout toolbar for specific webview url?

I have a Toolbar created in Linear Layout associated with a relative layout webview. How to hide this toolbar for specific urls for eg : 'index.php'
My Toolbar code is given below
I have tried many times and cant make it work properly with the given answers so updating the code with the xml layout code.
if (TextUtils.isEmpty(getString(R.string.toolbar))) {
showToolBar = false;
}
if (showToolBar) {
mSearch = (ImageView) findViewById(R.id.search);
mAdd = (ImageView) findViewById(R.id.add);
mProfile= (ImageView) findViewById(R.id.profile);
mHome= (ImageView) findViewById(R.id.home);
mSettings= (ImageView) findViewById(R.id.settings);
// ImageView mRefresh = (ImageView) findViewById(R.id.refresh);
mSettings.setOnClickListener(this);
mHome.setOnClickListener(this);
mProfile.setOnClickListener(this);
mSearch.setOnClickListener(this);
mAdd.setOnClickListener(this);
// mRefresh.setOnClickListener(this);
}
else {
LinearLayout llToolbarContainer = (LinearLayout) findViewById(R.id.toolbar_footer);
if (llToolbarContainer != null) {
llToolbarContainer.setVisibility(View.GONE);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mAdView.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
}
XML Layout code , please do help
<?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">
<FrameLayout
android:id="#+id/webview_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
tools:context=".universalwebview.MainActivity">
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none" />
</FrameLayout>
<LinearLayout
android:id="#+id/toolbar_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#fff"
android:orientation="horizontal">
<ImageView
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="#drawable/ic_action_home"
android:tint="#color/tintcolor" />
<ImageView
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="#drawable/ic_action_search"
android:tint="#color/tintcolor" />
<ImageView
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="#drawable/ic_action_add"
android:tint="#color/tintcolor" />
<ImageView
android:id="#+id/profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="#drawable/ic_action_profile"
android:tint="#color/tintcolor" />
<ImageView
android:id="#+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="10dp"
android:src="#drawable/ic_action_settings"
android:tint="#color/tintcolor" />
</LinearLayout>
<ImageView
android:id="#+id/image_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:visibility="visible"
android:src="#drawable/splash" />
</RelativeLayout>
In Your MainActivity Code you can't make Your Showtoolbar bool variable false by default.As that is the place where your bottom navigation is actually populating.So it may gives a run time error.Instead of that, make your Linear Layout hide when url contains "index.php".
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(url.contains("index.php")
{
findViewById(R.id.toolbar_footer).setVisibility(View.GONE);
}
else
{
findViewById(R.id.toolbar_footer).setVisibility(View.VISIBLE);
}
}
Call this under your WebViewClient .
You need to create a function , that will hide an tool bar. And create custom WebViewClient for WebView
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (url.contains("index.php")) {
hideToolBar();
}
}
};
Something like this. Not sure that you need onPageFinished, but you can find more info WebViewClient
Get url
Use url.contains("index.php") to judge
set showToolBar = false; or showToolBar = true;
Use if (showToolBar) {} else {}
Try this .
private boolean showToolBar;
private LinearLayout llToolbarContainer;
public void initWebView() {
llToolbarContainer = (LinearLayout) findViewById(R.id.toolbar_footer);
String url = "your_url";
if (url.contains("index.php")) {
showToolBar = false;
llToolbarContainer.setVisibility(View.GONE);
} else {
showToolBar = true;
llToolbarContainer.setVisibility(View.VISIBLE);
}
mSearch = (ImageView) findViewById(R.id.search);
mAdd = (ImageView) findViewById(R.id.add);
mProfile = (ImageView) findViewById(R.id.profile);
mHome = (ImageView) findViewById(R.id.home);
mSettings = (ImageView) findViewById(R.id.settings);
// ImageView mRefresh = (ImageView) findViewById(R.id.refresh);
mSettings.setOnClickListener(this);
mHome.setOnClickListener(this);
mProfile.setOnClickListener(this);
mSearch.setOnClickListener(this);
mAdd.setOnClickListener(this);
// mRefresh.setOnClickListener(this);
}

Categories