logo
down
shadow

Error in findViewById tried everything


Error in findViewById tried everything

By : Jane Fortier
Date : November 20 2020, 03:01 PM
it fixes the issue Method findViewById() is not implemented in class Fragment. That method is implemented for Activity or View
So, try the change below:
code :
public void onCreate(Bundle savedInstanceState) {
    ....
    EditText edit = (EditText) getActivity().findViewById(R.id.editText);
    ....
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_fingerp, container, false);

    EditText edit = (EditText) rootView.findViewById(R.id.editText);
    String edt = edit.getText().toString();
    File file = new File (myDir,edt);

    return rootView;
}
public void onActivityCreated (Bundle savedInstanceState) {
    ...              
    EditText edit = (EditText) getActivity().findViewById(R.id.editText);
    ...
}


Share : facebook icon twitter icon
Can someone explain to me the magic behind FindViewById(1) or FindViewById(2)?

Can someone explain to me the magic behind FindViewById(1) or FindViewById(2)?


By : Web Pipeline
Date : March 29 2020, 07:55 AM
I wish this help you It is an overall bad idea to use this approach with hard coded ids especially if you are not the one who set them as they are subject to change.
However, to answer the question to figure out the id to use, one option is to do a lot of guess and check work using the Android Studio debugger to manually traverse the view hierarchy. That would likely take a lot of time so a much easier approach is to just use the Hierarchy Viewer which is available in both Android Studio and Eclipse.
code :
View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2);
what is the difference between View.findViewById() and Activity.findViewById()?

what is the difference between View.findViewById() and Activity.findViewById()?


By : user3525968
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The View version searches the view you call it on and all subviews of it. The Activity one searches the top level view set in setContentView and all subviews of it. The Activity one is equivalent to calling View.findViewById on the contentView of the activity.
Its basically a convenience method to make it easier to search for an id within all the views of an activity without having to remember what the top view in it is.
Difference between view.findViewById(R.id....) and just findViewById(R.id...)

Difference between view.findViewById(R.id....) and just findViewById(R.id...)


By : user3749799
Date : March 29 2020, 07:55 AM
wish of those help findViewById always requires a context to find the view.
If you are calling this from a class which is extends the Activity class, you could just use findViewById, because Activity is the context.
Why findViewById() doesn't work as getActivity().findViewById() here?

Why findViewById() doesn't work as getActivity().findViewById() here?


By : user3924572
Date : March 29 2020, 07:55 AM
like below fixes the issue
In this code when I am using TextView text=(TextView)getActivity().findViewById(R.id.text1)
Android create a new Object from findViewById vs casting a findViewById

Android create a new Object from findViewById vs casting a findViewById


By : David Walters
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The two methods are essentially doing the same thing.
If you need to make repeated use of the TextView by setting multiple properties or events the first method is better to avoid multiple calls to findViewById. It is also necessary if you need to keep a reference to the View to update later in some other method.
Related Posts Related Posts :
  • Interrupt CompletableFuture with default value
  • Eclipse - Choosing servers in "Run on server" vs setting "Target Runtime"
  • Spring JPA doesn't validate bean on update
  • How is takeWhile different from filter?
  • Spring Scheduled Cron jobs firing at wrong time
  • JFrame window resizing on every compile. Different results every time
  • Kotlin unresolved reference :add after converting from Java code
  • How to use Neo4j APOC method " apoc.export.csv.query(query,file,config)" in Java program
  • Regex to include all spanish characters and number
  • Parsing and Mapping a JSON Object with Dynamic Properties
  • Which approach to building domain objects in Spring MVC is more correct?
  • Java Long Min and Max not exact as mentioned in docs
  • Selenium opens new tab after SendKeys
  • How to sort a large array of ints?
  • FitNessse Test can not find Fixture
  • Including Signed Libraries in Executable JAR with Maven
  • If and Else statement run on second iteration of while loop
  • Change class of disabled tab on change of dropdown value
  • Junit5 @ParameterizedTest How to pass array as one of parameter
  • Text message not being sent to a list of numbers but is sent when just one number is specified
  • Spring mapped servlet not called in jetty-maven-plugin
  • How to pace the consumption of a sqs queue using spring integration
  • Autowiring Not getting disabled using xml configuration
  • Maze solve and shortest path with Java BFS
  • Spinner updating only on user actions
  • Why are Java rules for protected access such as they are?
  • Modify parameter of method by value in annotation aspectJ
  • How to send sensitive data to a Liferay portlet from outside the Liferay portal
  • Does a server connection stay open if created inside a method?
  • JAR manifest Class-Path, use folder instead of jar
  • How to do a bulk update in Firestore
  • ItemArray.checklist.add() not appending string to ArrayList
  • How to move something on screen without other picture staying there
  • SpringBoot : No matching bean found exception
  • Implementing the Clonable interface, but don't have to override the clone() method
  • how can i get this code to choose a random word once from each array to print a sentence?
  • Static class to get connections from connection pool
  • Unable to start Chrome browser with user profile in Selenium
  • How to pass a object to be created as a parameter for a method in Java?
  • How to retry with hystrix
  • Loading key to KeyStore fails on Android Oreo
  • Spring+Velocity unsuccessful attempts to save object
  • Private constructor in Kotlin
  • Jetty:run fails with NoSuchMethodError with Spring 5
  • Cannot upload my Web Applicartion in Jboss7 EAP7 EAP
  • How to load a certificate from "Credential storage"?
  • Call Genexus procedure stub in Java environment
  • JavaFX clipping produces a 'lottery scratch ticket'-Effect
  • Using DateTimeFormatter on january first cause an invalid year value
  • Get all the output from Watson conversation using java
  • Java unable to open main class and jar file
  • How to override @override method from activity into another class
  • Adding Runtime VM parameters to intellij for Java 9
  • Java IBM MQ Client connected but not getting messages from queue
  • Questions of Tomcat SSL configuration
  • Stale JNLP files for <extension> (since Java 9?)
  • Properly set (system) properties in JUnit 5
  • Spring MVC Model within POST Method is empty
  • VSTS buildagent: Java 9
  • java.lang.NumberFormatException: For input string: "id" for Hibernate
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org