Checkbox onClick xml method calling not working (Unresolved Method) - android-layout

I have a map fragment inside a Drawer activity, I just added a checkbox to the mapFragment layout like so:
<?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:id="#+id/map_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mapFragment">
<!-- TODO: Update blank fragment layout -->
<fragment
android:id="#+id/map1"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:tag="home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context="com.tesseract.psiclops.zero.Main" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="87dp"
android:background="#drawable/edittext_designtst"
android:ems="10"
android:hint=" ■ ¿Qué buscas hoy?"
android:inputType="textPersonName"
android:textColor="#806b63"
android:textColorHint="#806b63"
android:textColorLink="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="#+id/follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:checked="true"
android:onClick="followIO"
android:text="Sígueme"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I have specified the onClick method "followIO" to trigger everytime the checkbox its checked/unchecked so the user can activate/deactivate camera updates of the map kind of like a "Follow me" checkbox.
I've declared the method inside the map fragment code since its the related activity(right?)
public class mapFragment extends Fragment implements OnMapReadyCallback, LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
.
.
.
public void followIO(View view){
boolean checked = ((CheckBox)view).isChecked();
if(checked){
//Updates on
}else{
//Updates off
}
}
}
but I still get the warning: "Cannot Resolve symbol followIO".
When I try to uncheck the checkbox the app crashes and throws this exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tesseract.psiclops.zerov2, PID: 5473
java.lang.IllegalStateException: Could not find method followIO(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatCheckBox with id 'follow'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:6256)
at android.widget.CompoundButton.performClick(CompoundButton.java:134)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I'm still pretty new at android and I couldn't find other solution to my problem so I hope someone can help, Thank you in advance!

I just found out the answer, I'll post it here in case someone find it useful:
Apparently xml method declaration doesn't work well with fragments, the best aproach is to relate a variable to the checkbox and then call an onCLicklistener. Then I called the method from there like so:
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
.
.
.
CheckBox follow;
follow=view.findViewById(R.id.follow);
follow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
followIO(v);
}
});

Related

How to onclick on pop up fragment ? Android studio

I have a popup.xml that have sign in and sign up button. This pop up will be shown when i click on certain function. Now the problem is i cant OnClick on the sign in and sign up button. I want to redirect to login activity when i click on sign in on the pop up fragment. I tried to create a class to the popup.xml and OnClick on sign in button but it seem like not working at all. It doesnt even triggered the OnClick function because Log.d("dwfsd","wefwef"); doesnt show at all.
Pop Up Image
My loginpopup.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="350dp"
android:layout_height="300dp"
xmlns:tools="http://schemas.android.com/tools"
android:layout_gravity="center"
android:background="#drawable/circlebackground"
tools:context=".loginpopup">
<ImageView
android:id="#+id/loginLogo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:src="#drawable/foxsplash" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/loginLogo"
android:paddingTop="30dp"
android:gravity="center">
<Button
android:id="#+id/signIn"
android:layout_width="150dp"
android:layout_height="55dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="56dp"
android:textColor="#color/white"
android:textSize="24sp"
android:padding="3dp"
android:focusable="true"
android:textAllCaps="false"
android:background="#drawable/rounded_rectangle"
android:text="Sign In"/>
<Button
android:id="#+id/signUp"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="56dp"
android:textColor="#color/white"
android:textSize="24sp"
android:padding="3dp"
android:focusable="true"
android:textAllCaps="false"
android:background="#drawable/rounded_rectangle"
android:text="Sign Up"
android:layout_toEndOf="#+id/signIn"/>
</RelativeLayout>
</RelativeLayout>
loginpopup.java:
public class loginpopup extends AppCompatActivity {
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginpopup);
button =(Button) findViewById(R.id.signIn);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("dwfsd","wefwef");
openActivity();
}
});
}
private void openActivity() {
Intent intent = new Intent(this, login.class);
startActivity(intent);
}
}

What's this layout, any example about this one?

https://drive.google.com/open?id=1iCM6GlT-iAXxNWw7qAt165Q1PVWhMrSp
What's loading(blur) and then show icon layout?
How to create one like this?
You could start checking Shimmer effect. This help you showing any item layout structure as a placeholder while you are doing some extra work (or loading something)
Result:
How to do it:
First, add facebook Shimmer library to build.gradle:
dependencies {
implementation 'com.facebook.shimmer:shimmer:0.1.0#aar'
}
Then create you placeholder_layout.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="match_parent"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp">
<View
android:id="#+id/thumbnail"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="16dp"
android:layout_marginTop="10dp"
android:background="#dddddd"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/thumbnail"
android:layout_marginTop="10dp"
android:orientation="vertical">
<View
android:layout_width="100dp"
android:layout_height="8dp"
android:background="#dddddd" />
<View
android:layout_width="30dp"
android:layout_height="8dp"
android:layout_marginTop="5dp"
android:background="#dddddd" />
</LinearLayout>
</RelativeLayout>
Next, in your activity layout, add the ShimmerFrameLayout with your placeholders.
<com.facebook.shimmer.ShimmerFrameLayout
android:id="#+id/shimmer_view_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:orientation="vertical"
shimmer:duration="800">
<!-- Adding 7 rows of placeholders -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/data_placeholder_layout" />
<include layout="#layout/data_placeholder_layout" />
<include layout="#layout/data_placeholder_layout" />
<include layout="#layout/data_placeholder_layout" />
<include layout="#layout/data_placeholder_layout" />
<include layout="#layout/data_placeholder_layout" />
<include layout="#layout/data_placeholder_layout" />
</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
Finally manage when to show or hide the ShimmerFrameLayout in your Activity/Fragment class:
public class MainActivity extends AppCompatActivity {
private ShimmerFrameLayout mShimmerViewContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mShimmerViewContainer = findViewById(R.id.shimmer_view_container);
// Stop Shimmer effect whenever you want. e.g. when data
// is received from web service
mShimmerViewContainer.stopShimmerAnimation();
mShimmerViewContainer.setVisibility(View.GONE);
}
#Override
public void onResume() {
super.onResume();
mShimmerViewContainer.startShimmerAnimation();
}
#Override
protected void onPause() {
mShimmerViewContainer.stopShimmerAnimation();
super.onPause();
}
}
NOTE: Don't forget to start and stop the component when the view is no longer visible. Use onResume() and onPause()
Hope this helps you.
Source: https://medium.com/mindorks/android-design-shimmer-effect-fa7f74c68a93

Radio Button and TextField Android-studio

How can I make a radio button group and a TextField, so that whenever I click on TextField the radio button automatically changes from one to another?
Please give me a block of code for this.
If I understood your question correctly, you want the radioButton checked status change once the textView click. You can achieve by this way.
public class MainActivity extends Activity {
private RadioGroup radioSexGroup;
private RadioButton radioSexButton,male,female;
private TextView btnDisplay;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioSexGroup=(RadioGroup)findViewById(R.id.radioGroup);
btnDisplay=(TextView)findViewById(R.id.textView3);
male = (RadioButton)findViewById(R.id.radioButton);
female=(RadioButton)findViewById(R.id.radioButton2);
btnDisplay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int selectedId=radioSexGroup.getCheckedRadioButtonId();
radioSexButton=(RadioButton)findViewById(selectedId);
if(radioSexButton.getText().toString().equals("Male"))
{
female.setChecked(true);
}
else
{
male.setChecked(true);
}
}
});
}
}
activity_main
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="58dp"
android:weightSum="1"
android:id="#+id/radioGroup"
android:layout_alignRight="#+id/textView3"
android:layout_alignEnd="#+id/textView3">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="55dp"
android:text="Male"
android:id="#+id/radioButton"
android:layout_gravity="center_horizontal"
android:checked="false"
android:textSize="25dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/radioButton2"
android:layout_gravity="center_horizontal"
android:checked="false"
android:textSize="25dp"
android:layout_weight="0.13" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me "
android:id="#+id/textView3"
android:textSize="35dp"
android:layout_below="#+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"></TextView>
</RelativeLayout>
https://www.tutorialspoint.com/android/android_radiogroup_control.htm
check this link , to use radio group with textviews

getBaseline of TextView returns -1

I am trying to align two TextView one is inside HorizontalScrollView, and both are children of LinerLayout .
When I am trying to call getBaseLine of TextView inside onWindowAttached of RecyclerView Adapter it always returns -1.
Yes, the parent view of TextView, LinerLayout has android:baselineAligned="true"
Edit : Adding Code
Layout
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="6dp"
android:paddingEnd="10dp"
android:baselineAligned="true"
android:paddingStart="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/outerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
<HorizontalScrollView
android:id="#+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/inlineTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
/>
</HorizontalScrollView>
</LinearLayout>
Code in RecyclerView Adapter
#Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
{
super.onViewAttachedToWindow(holder);
if(holder instanceof MyHolder)
{
dostuff((MyHolder)holder);
}
}
private void dostuff(QACommentViewHolder holder)
{
int baseline = holder.outerTextView.getBaseline();
}
View is not measured when onViewAttachedToWindow is called, hence it is returning -1.
Better approach would be.
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
.
.
.
viewHolder.itemView.post(new Runnable()
{
//put your code here

Android - UI Disappear after startActivity

I'm starting an simple ACTION.VIEW activity to show up the web browser.
But when the user press the "back" key, it returns to my initial application. The application is working perfectly except that all the main UI elements have disappeared.
Anyone knows why ?
Here's how I start the web browser :
//Go to web page
ImageButton web = (ImageButton) _gears.findViewById(R.id.Web);
web.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v)
{
try
{
String url = "http://apps.toonboom.com/flip-boom-lite-ipad";
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse(url);
i.setData(u);
_mainActivity.startActivity(i);
}
catch (ActivityNotFoundException e)
{
// Raise on activity not found
Toast.makeText(_mainActivity.getApplicationContext(), "Browser not found.", Toast.LENGTH_SHORT);
}
}
});
When coming back from that browser page, onStart() and onResume() are called normally. What I don't understand is that the back and home button lifecycle works perfectly. The user can manually go away of the app and come back without any UI problems. The problem only occurs when coming back from that startActivity() call ?
Also, I don't need to retain any specific UI values....I just want them to be present in the layout ;)
EDIT
I have a gles view that I use to draw and I think it display itself in front of the other UI elements....But I don't understand why if that is the case....
Here's a piece of the xml and the onCreate method :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/MainLayout">
<!-- This is a dummy layout so we can add our custom GlView dynamically to this relative position -->
<LinearLayout
android:id="#+id/SurfaceViewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<!-- This is a dummy layout so we can add the timeline dynamically to this relative position -->
<HorizontalScrollView
android:id="#+id/TlScroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_margin="0dip"
android:padding="0dip"
android:scrollbars="none"
android:fillViewport="false"
android:scrollbarFadeDuration="0"
android:scrollbarDefaultDelayBeforeFade="0"
android:fadingEdgeLength="0dip"
android:scaleType="centerInside">
<!-- HorizontalScrollView can only host one direct child -->
<LinearLayout
android:id="#+id/TimelineContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_margin="0dip"
android:padding="0dip"
android:scaleType="centerInside"/>
</HorizontalScrollView >
<RelativeLayout
android:id="#+id/BottomTools"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/TlScroller" >
<ImageButton
android:id="#+id/PaletteBtn"
android:layout_width="30dip"
android:layout_height="30dip"
android:background="#android:color/transparent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dip"
android:layout_marginBottom="60dip"
android:src="#drawable/palette44x44"
android:scaleType="centerInside"/>
<RelativeLayout
android:id="#+id/PadLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:src="#drawable/pad_btn"
android:scaleType="centerInside">
<ImageButton
android:id="#+id/PadBtn"
android:layout_width="75dip"
android:layout_height="75dip"
android:background="#android:color/transparent"
android:layout_centerInParent="true"
android:src="#drawable/pad_btn"
android:scaleType="centerInside"/>
<TextView
android:id="#+id/FrameCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dip"
android:padding="0dip"
android:layout_centerInParent="true"
android:textColor="#000000"
android:text="#/x"/>
</RelativeLayout>
<ImageButton
android:id="#+id/PreviousBtn"
android:layout_width="40dip"
android:layout_height="40dip"
android:background="#android:color/transparent"
android:layout_toLeftOf="#+id/PadLayout"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dip"
android:src="#drawable/previous_btn"
android:scaleType="centerInside"
android:scaleHeight="30%"
android:scaleWidth="30%"/>
// Goes like that with other ImageButton till the end bracket
= = =
#Override protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
//Set the main layout element
setContentView(R.layout.ui);
// Then most buttons are created like this . . .
//Create the tools pop-up menu
ImageButton toolBtn = (ImageButton) this.findViewById(R.id.CurrentToolBtn);
_tools = new ToolsPopup(toolBtn);
}
When you launching a web browser it uses a lot of memory so android killing your app, when it is going back to activity it recreates it. So you should save your dynamically added views using onsaveinstancestate and onrestoreinstancestate.
onSaveInstanceState () and onRestoreInstanceState ()

Resources