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.
Related
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
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 want to display banner(images moving in x direction) in my application. For that i am using ViewFlipper with Translation animation. Please find my below code..
my layout: banner.xml
<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" >
<ViewFlipper
android:id="#+id/banner_image"
android:layout_width="match_parent"
android:layout_height="258dp" />
</RelativeLayout>
In animation: in_from_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="3000"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
Out Animation: out_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="3000"/>
</set>
My Java Code
public class BannerView extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.banner);
ViewFlipper myViewFlipper = (ViewFlipper) findViewById(R.id.banner_image);
//Setting first image in viewFlipper
ImageView imageView1 = new ImageView(HomeView.this);
imageView1.setImageDrawable(getResources().getDrawable(R.drawable.img1));
myViewFlipper.addView(imageView1);
//Setting second image in viewFlipper
ImageView imageView2 = new ImageView(HomeView.this);
imageView2.setImageDrawable(getResources().getDrawable(R.drawable.img2));
myViewFlipper.addView(imageView2);
myViewFlipper.setAutoStart(true);
//Setting in and out animation
myViewFlipper.setInAnimation(HomeView.this,R.anim.in_from_right);
myViewFlipper.setOutAnimation(HomeView.this,R.anim.out_to_left);
//Starting the view filpper to rotate
myViewFlipper.startFlipping();
}
}
Here my problem is,
When i set the duration for in and out animation as "5000", ViewFilpper's behavior is changing like the below,
Image start to move slowly and ending quickly.
I dont know where i am missing. I want to slow down the speed. Please help me resolve the issue.
Update: I whipped up some sample code and there is a big stutter halfway through as if the 2nd view is forcibly moved to catch up to the 1st view. After much trial and error I found that setting android:flipInterval="5000" in the viewflipper xml properties fixed it. I can only assume that the default flipInterval is shorter than 5000 and hence the issue.
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="match_parent"
android:layout_height="258dp"
android:flipInterval="5000" >
If you still find the animation not smooth enough:
Put this in your xml for the translate animation:
android:interpolator="#android:anim/linear_interpolator"
And then
android:startOffset="1000"
to slide_out_to_left so it waits a bit before continuing.
Thanks for your reply. I found the solution for my problem. Please find my answer below.
I have changed my interpolator in xml as below:
android:interpolator="#android:anim/decelerate_interpolator"
And then i used android:flipInterval="5000" in my viewflipper solved my problem.
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>