I've used the Fullscreen Activity to create a project in Android Studio 2020.3.1. On buld of the app, I get "Unresolved reference: LastChange". The 3 lines pointed to (in FullscreenActivity.kt) are:
override fun onConfigurationChanged(newConfig: Configuration) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
LastChange.setText("Landscape")}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
LastChange.setText("Portrait")}
else {
LastChange.setText("Unrecognized")}
super.onConfigurationChanged(newConfig)
}
The TextView (in activity_xml) is coded as:
<TextView
android:id="#+id/LastChange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="#string/LastChangeText"
android:textSize="24sp" />
LastChangeText (in strings.xml) is defined as:
<string name="LastChangeText">N/A</string>
Although your textView has "LastChange" id, that's not the way you call it from activity.
At "onCreate" method, after super.onCreate(), you'll need:
setContentView(R.layout.<YOUR_LAYOUT_NAME>);
val lastChangeTextView = (TextView) findViewById(R.id.LastChange);
And, after that, you can call methods on "lastChangeTextView".
lastChangeTextView.setText("Landscape")
Strongly recommend taking a look at Documentation:
https://developer.android.com/guide/topics/ui/declaring-layout
Related
what I am trying to do is show a custom card in a recyclerview.
I can see it on the design view on android studio, but no when the emulator runs.
I just need to display de listItem.
Is is posible? if so, any help or suggestion would be great, thanks.
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rcvPoolVariables"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="22dp"
android:layout_marginStart="17dp"
android:layout_marginEnd="17dp"
tools:listitem="#layout/row_pool_objectives"
app:layout_constraintTop_toBottomOf="#+id/containerVariableAndWeeks"
app:layout_constraintBottom_toBottomOf="parent"/>
1.xml
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/categoryview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:listitem="#layout/innercategorylist">
</androidx.recyclerview.widget.RecyclerView>
2.java file
CategoryModel[] myListData1 = new CategoryModel[]{
new CategoryModel( R.drawable.kiwi,"kiwi"),
new CategoryModel(R.drawable.watermelon,"watermelon" ),
new CategoryModel(R.drawable.strawberry,"strawberry")
};
innerCategoryAdapter = new InnerCategoryAdapter(myListData1, new InnerCategoryAdapter.HomeAdapterInterface() {
#Override
public void onRowClick(int searchText) {
}
});
3.Adapter class id define and assign and model class to variable getter setter set
If the "preliminary version" is shown in the design tab, then there are no errors on the part of xml documents. It's in "regular" code part. I think the error lies in the output of elements on the device - either you do not pass data objects for output in recycler view, or there is an error in the processing of this data. Check the recycler view classes architecture and code of an adapter class. Also read this guide, I hope it'll help you.
When I take the screenshot. The part where there is camera preview goes black.
private fun getScreenShot(view: View): Bitmap {
val returnedBitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
PixelCopy.request(window, returnedBitmap, {}, Handler(Looper.getMainLooper()))
return returnedBitmap
}
activity_main.xml
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragment"
android:name="com.google.ar.sceneform.ux.ArFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Change the first parameter in the function
PixelCopy.request(window, returnedBitmap, {}, Handler(Looper.getMainLooper()))
to
PixelCopy.request(arFragment.sceneView, returnedBitmap, {}, Handler(Looper.getMainLooper()))
it's my EditText.
I run the app don't type anthing
when I sout gettext().toString
I got really nothing
not null or "" why?
<EditText
android:id="#+id/ed_account"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/bg_edittext"
android:hint="#string/employeeHint1"
android:inputType="number"
android:text=""
android:paddingLeft="10dp" android:paddingStart="10dp"
/>
this is for someone to type some info for me to do something
I use hint, I don't want type anything to over the hint
and I have to make sure user to type something.
Try to modify this line
android:text="some text...."
your question is not clear, am sorry but please improve your english. And without the java code, am not sure i got your problem right, but try using this to check if the EditText is null:
EditText usernameEditText = (EditText) findViewById(R.id.editUsername);
sUsername = usernameEditText.getText().toString();
if (sUsername.matches("")) {
Toast.makeText(this, "You did not enter a username", Toast.LENGTH_SHORT).show();
return;
}
I recently purchase a source code for a quiz app, doing so with no experience. The app allows video to be played, but requires you to "tap to play", I would like for the video to play on the same screen as the question. How do I change this and can I change this in this line of code? New to this, so if you need any additional info, let me know.
else if(question.questionType == 3) {
mSmallLayout.setVisibility(View.VISIBLE);
mTapText.setText(R.string.tap_to_play);
File file = new File(getExternalCacheDir() + "/delete" + mCurrentQuestion);
if(!file.exists()) {
mSmallImage.setImageURI(Uri.fromFile(file));
} else {
mSmallImage.setImageResource(R.drawable.videooverlay);
}
Then you need to open it using an Android Edition Platform, The code is like:
JAVA:
public void onClickBtn(View v)
{
Toast.makeText(this, "Lets try").show();
}
}
Button[Onclick function]:
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/btn"
android:onClick="onClickBtn" />
</LinearLayout>
And video example:
Playing a video in android
// Additional info: The Android Manifest is a android XML to execute the JAVA code, To work on you need check the Android dev's page and check every function, An function to be ready, Need to be set righty. Thank you!
I am tyring to achieve two alignments in the title of an android app. The title according to my requirement needs to have a 'name' which is left aligned and a 'version number' which is right aligned.
So far what I have tried doing is to test whether the label attribute of the application tag of the AndroidManifest.xml files accepts html, but it does not seem to :(. Also from some of the other similar questions I came to know that the style of the title could be changed using a custom theme. But this does not answer my question:
"Can we have two different alignments (say left and right), or for that case two different themes, to the parts of the application name?"
P.S: A screenshot of the desired application title is attached below.
You can create custom title bar ..
here is sample code.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.i_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.i_title);
final TextView titleLeft = (TextView) findViewById(R.id.title_left);
final TextView titleRight = (TextView) findViewById(R.id.title_right);
titleLeft.setText("Checker");
titleRight.setText("Version 5.44");
}
i_title.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/title_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="app name" />
<TextView
android:id="#+id/title_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="app version" />
</RelativeLayout>