Android Studio can't resolve new XML layout - android

I'm making customized contacts app, which one of it's features are to send SMS.
All was going good until I wanted to create my sixth XML layout which 'setContentView' couldn't resolve, even if I'm deleting the layout and auto-creating it by using Alt+Enter.
I've looked up for solutions in here.
It's not related to R.java.
I made all to make sure the layout name is not misspelled.
setContentView(R.layout.activity_sendsms);
The layout is 100% there but still I'm getting from Android Studio the error:
Cannot resolve symbol 'activity_sendsms'
the eror and the show it's in the right place
Do I need to import something which I'm not doing right? (all others .java file imports are pretty much the same)
The imports:
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

Apparently restarting Android Studio did the trick.
Thanks all for answering.

Related

How to import all top level functions in another kotlin file

I have two files,
AzimuthAct.kt and Mathf.kt, all of my custom functions are in Mathf.kt.
how do you import all function to another .kt file?
something like:
import com.company.appname.Mathf.* // <-- doesnt work
import kotlin.math.* // work
this what i mean
Top level functions are members of the package declared at the top of their containing file
In order to use them outside their own package, you can import them individually as import kotlin.math.sin or if you want to import them all then you can use star import after package name as import kotlin.math.*
In your case if you want to import all the top level functions declared in Mathf file then you need to use a star import on package as
import com.company.appname.*
Now you should be able to access all your top level functions from Mathf.kt

Question on importing two classes with the same name - android.graphics.Color

I currently have a imported color class from another Android Library:
import com.google.ar.sceneform.rendering.Color;
but I need to import another color class:
import android.graphics.Color;
but after typing this import, it gives me the error:
so I have to end up removing the second import and use it manually like this:
mBtnColor.setColorFilter(android.graphics.Color.parseColor(color));
is there a way I can import both classes? or maybe use the second import without typing android.graphics.Color?
Create two classes: one inherits the first Color and does nothing and is called AndroidGraphicsColor and the other one inherits the appropriate class and is called AndroidSceneFormRenderingColor. Then use them.

MainActivity not reading Subfolders Android Java

I created an application that uses the Room, ViewModel approach. I created subfolders to organize my code as shown in the photo:
How do I make my Main Activity recognize the code created in the subfolders? I tried invalidate caches/restart already and tried many times to rebuild the project.
There was an issue when I created my folders. I used New->Folder->Java Folder when the right process should be New->Package
You have to write an import statement for the classes to be recognized:
import com.example.laundry.data.ViewModel.CustomerViewModel
I think there are various ways to solve this problem.
Process 1.
For your Adapter import this
import com.example.laundry.adapter.CustomerListAdapter;
For your ViewModel import this
import com.example.laundry.data.ViewModel.CustomerViewModel;
Process 2
If you write down your adapter/model class name it will show some popup. From there you can select.
just like when I tried to import InfiniteScrollAdapter I got these options
Process 3
Please check if you have already import that adapter/model class with the different package names. Just delete that line and import again with alt+ enter

Required:android.app.Fragment error

I am working on a simple application of tabs but when I do the return I throw this error I do not really know how to solve it, I read something about importing and you put "import android.app.Fragment;" But I already have it that way. I would appreciate if I can resolve my doubt to the point of this error thanks
As I cannot comment yet I will give a full answer altho you haven't provided full details I can guess your problem.
Answer:
You probably have different imports on your Fragment class and on your Activity as from your pic on your activity you import this:
import android.app.Fragment;
and on your fragment you probably import this:
import android.support.v4.app.Fragment;
meaning its not the same class therefore your ide yells that you have a class mismatch
you should import only one of these on both your activity and fragment..
gl!

Android Studio prevent import statements wrapping

I used Android Studio wrapping feature to ensure code does not exceed 120 characters. This works fine for almost anything, but Android Studio keeps wrapping import statements which is ugly. I would instead prefer to say to Android Studio to never wrap import statements.
current:
import com.acme.projet.ui.very.long.package.name
.InstallationCoreFeatureActivity;
import com.acme.projet.ui.very.long.package.name
.InstallationSelectorActivity;
import com.acme.projet.ui.very.long.package
.InstallationOtherFeatureActivity;
wanted:
import com.acme.projet.ui.very.long.package.name.InstallationCoreFeatureActivity;
import com.acme.projet.ui.very.long.package.name.InstallationSelectorActivity;
import com.acme.projet.ui.very.long.package.InstallationOtherFeatureActivity;
Does anybody know if it's possible and if possible, how to achieve this?
Edit: To crazy reviewer/editer, the wrapping in the current code example is done on purpose.

Categories

Resources