Can't all import - Android Studio - android-studio

First, the purpose is to get these views.
<TextView
android:id="#+id/Hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textSize="100dp" />
This way I can bring it.
val textView: TextView = findViewById(R.id.Hello)
But I want to import the entire XML file at once.
So I thought that typing Hello. would be an automatic import function, but it doesn't work.
Is there any way to solve this?
The alt+enter method did not solve it.
What is displayed by saying alt+enter
enter image description here

Typing "Hello" wont work as you have assigned the name 'textView' to that particular TextView,
I recommend changing the code to val Hello: TextView = findViewById(R.id.Hello)

Related

What is the name of this sliding selection list?

I want to implement this type of sliding selection list in my kotlin based android studio app. but, I don't know what actually it is. so, plz help me
Its Called Spinner
In Xml File implement like this
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Follow this link for more details
https://www.geeksforgeeks.org/spinner-in-kotlin/

Android Studio 3.6 - how use layouts in Design Palette?

I am new to Android development and Android studio. I'm using Android Studio 3.6.1 . I'm having trouble understanding the "Layouts" options in the Design Palette. First, I don't see a "RelativeLayout" option. I realize many feel this is superceded by the ConstraintLayout, but it seems to me it should be a choice. Second, I don't see how to even use these layout options. If I drag one to an existing design, nothing happens. I thought maybe it would replace the root layout, but doesn't seem to. It doesn't create a child layout (if such a thing is possible). My code is just a simple "MainActivity" class with "setContentView(R.layout.activity_main);" in the onCreate() method. I have been tinkering with the activity_main.xml file to learn UI concepts. I can type in manual changes to change the layout to RelativeLayout, but it wasn't obvious what the classpath of the RelativeLayout class was, it is not in the same package as the ConstraintLayout class. I'm trying to use the power of the Android Studio IDE to discover options and build code, but I'm not finding how to use it for Layout options. I tried emptying the "activity_main.xml" file and then dragging a Layout from the palette, but nothing happens. I can delete the "activity_main.xml" file and create a new one, but when it prompts for a layout, there is no discovery to help choose one, it seems you have to know the package.
How can these Layouts in the Design Palette actually be used in the IDE? Can RelativeLayout be added to the list? Are there other missing Layouts?
package com.example.test;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</android.widget.RelativeLayout>
Something changed and I can now right-click a Layout and "add to design" or drag it to the design. I can also right-click the Layout in the component tree and convert to another layout, including RelativeLayout. I had added a Calendar component to my design for the heck of it and built and run in the emulator. After that, I deleted the Calendar and found I was able to now drag the layout components or convert the root component. So I'm comfortable with use of Layouts in the Palette. I am still unclear how to discover Layouts when creating a new layout XML file when it asks for "root tag". But I realize you don't need a full path, just the class name it seems, apparently the IDE finds the class. The glue behind the scenes I'll need to learn more about.

How to get rid of the warning "cannot resolve symbole 'id/andr'" for ExpandableListView"

An app uses ExpandableListActivity, and the usage of ExpandableListView is standard based on the document:
<ExpandableListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:divider="#android:color/transparent"
android:dividerHeight="5dip"
android:layout_marginTop="10dip">
</ExpandableListView>
Android Studio 3.2 has the following warning:
How can I get rid of the warning?
This is probably a typo. Change it to:
"#android:id/empty"
and
"#android:id/list"
See also https://developer.android.com/reference/android/app/ListActivity
ListActivity has a default layout that consists of a single,
full-screen list in the center of the screen. However, if you desire,
you can customize the screen layout by setting your own view layout
with setContentView() in onCreate(). To do this, your own view MUST
contain a ListView object with the id "#android:id/list" (or R.id.list
if it's in code)
I don't know what is ( id="#id/android:list")
give it an normal id ( #+id/androidlist )
and handle it in your code
but if you learn how to work with ExpandableListView
I prefer this link tutorial for you ExpandableListView Link
GL sir

Android Studio Kotlin synthetic view variable refresh/regenerate

After changing the view's type, there are build errors that the variable is still an old type. How can I force Android Studio to refresh/regenerate the variables with current types?
For example,
<ImageView id="#+id/myView>
and in code
myView.setImage = someImage
Now, I change the type in the XML editor,
<TextView id="#+id/myView>
Now this line causes an error like myView has no "setImage" method, because it still thinks myView is a TextView.
myView.setText(some text);

Monodroid: Programatically add custom controls to a layout with horizontal and vertical centering

I have an ImageView inside a RelativeLayout that I added programmatically (The ImageView is added by code, not the RelativeLayout.)
If I had added the ImageView by XML, I would have done this:
<ImageView
android:id="#+id/login_loadingimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/imagefilename"
android:visibility="invisible"
/>
But now I want this done programtically. How do I get the centering right? I have tried creating RelativeLaout.Parameters but whe I create them using
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(this, null); //[1]
p.AddRule(...);[2]
An exception is thrown at line 1. In addition I wouldn't know how to apply these LayoutParameters on ViewGroup.LayutParameters anyway.
Also, I cannot just make ViewGroup.LayoutParameters because
1. They do not seem to have the Centering (Horizontal and Vertical) elements I need.
2. Every example seems to indicate there is a Constructor that simply takes Layout_Width and Layout_Height as parameters, but there is not.
Before someone says to add a layout first, please tell me how to center the layout in code as well. Thanks.
Please help.
The way to do it is simple:
Create xaml you want of JUST the component - put the file in the layout folder.
Then use the inflating service to inflate the control inside the code you want (make sure to create the LayoutInflator as follows):
LayoutInflater _inflatorservice = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
Then simply call this:
_inflatorservice.Inflate(Resource.Layout.[control], parent);
and Bob is your mother's brother!

Resources