This code and minor variations thereof exist in many forums on the net. When I launch it on my Samsung Galaxy Tab 2 (Android 4.1.1), the bar appears, the thumb can be moved, the position is reported, etc. All good, EXCEPT, the thumb never disappears. Mine manifests as a little blue circle, which I can slide along a bar, but it leaves a trail of "thumbs" behind it: one at each of the possible integer locations in the range of the seekbar.
Is the code incomplete? Is there something we have to add to manually redraw the component?
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
public class FullscreenActivity
extends Activity
implements SeekBar.OnSeekBarChangeListener {
SeekBar seekBar;
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
seekBar=(SeekBar)findViewById(R.id.seekbar);
textView=(TextView)findViewById(R.id.textview);
seekBar.setOnSeekBarChangeListener(this);
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// Notify that the progress level has changed.
textView.setText(textView.getText()+"\n"+"SeekBar now at the value of:"+progress);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// placeholder
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// placeholder
}
}
Here's the layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SeekBar
android:id="#+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
android:max="31"
android:progress="15" />
<TextView
android:id="#+id/textview"
android:layout_width="fill_parent"
android:layout_height="270dp"
android:layout_marginTop="150dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" />
</FrameLayout>
Screenshot of the effect:
Update The effect is the same on a ZTE-BLADE running Android 2.2. Of course teh default graphic is different (the gray / orange seekbar with a more square "thumb") but the thumbs remain behind at all the points I've scrolled through.
The residual garbage clears if I change the screen orientation, which makes me think it just needs a redraw. Can anyone help?
So, I copied and pasted my example code line-at-a-time into a new project, running it as I went, hoping to find the line which failed.
Got the whole thing pasted in and it worked perfectly. No problems in the seekbar.
On comparing the projects, the only difference was that the AndroidManifest.XML file contained the line
android:theme="#style/FullscreenTheme"
in the activity section. So, I went back to my original (faulty) project and took this line out. Now the project works fine.
I have my answer: the code is complete and there's nothing we need to add to make it redraw.
I still don't understand why this line had that effect and now I have a horrible white background when I wanted black.
Related
I made a simple app using Cards in Material Components in Android. When I try to run it in my "OnePlus AC2001" mobile, I'm getting this error in logcat.
2021-01-31 17:28:59.544 26933-26933/? E/rialdesigncard: Unknown bits set in runtime_flags: 0x28000
But I'm not getting any error when I run the app in the emulator.
This is my MainActivity.java file:
public class MainActivity extends AppCompatActivity {
CardView cardView;
TextView textView;
CheckBox checkBox;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
cardView = findViewById(R.id.my_card_ui);
textView = findViewById(R.id.title_text);
checkBox = findViewById(R.id.checkbox);
cardView.setOnClickListener(v -> {
checkBox.setChecked(checkBox.isChecked()? false: true);
textView.setText("First title");
});
}
}
This is my ActivityMain.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:id="#+id/my_card_ui"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkable="true"
android:clickable="true"
android:focusable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="30dp">
<CheckBox
android:id="#+id/checkbox"
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView
android:id="#+id/title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title 1"
android:textColor="#color/black"
android:textSize="30dp"
android:textStyle="bold" />
<TextView
android:id="#+id/title_para"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I am a paragraph and I am in a card. I am a paragraph and I am in a card. I am a paragraph and I am in a card."
android:textColor="#color/purple_700"
android:textSize="20dp" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
I couldn't find the solution to this error anywhere. Please help me solve this.
I have been consistently seeing this error for some time now (OnePlus device), but I haven't been able to find a solution either. The error does not seem to impact the app in any way though.
Additional point of information:
I have observed that this error appears in the Logcat whenever I Run/Debug the app on a real device, but it does not show up consistently in the Run/Debug consoles. I haven't tried to check (as you have) if the error is replicated when using an emulator.
Also, my Logcat shows the Unknown bits set in runtime_flags: 0x20000 error for many other packages as the device is running. Some examples: .android.dialer, oneplus.weather, twitter.android, and so on.
This is what I've found out so far:
From the ARM DS5 DUI0446U Debugger User Guide, a possible memory map for internal RAM can be between 0x8000 and 0x28000. I'm not from a computer engineering background, and I'm not sure if this is a relevant direction for understanding the problem further. Searching the Android Runtime (ART) site (this, or in general, this) yielded no useful results.
For a related error, by following this answer to the ART source code, 0x28000 seems to be related to either the DEBUG_IGNORE_APP_SIGNAL_HANDLER flag or the DISABLE_TEST_API_ENFORCEMENT_POLICY flag (line 154-155 as of this time of this post). [E.g., 1 << 17 is 0x20000]
I don't have a deeper understanding of the either of the two flags. Nevertheless, the 0x20000 error seems to be pretty commonplace in production apps. While this is not an indication that the 0x28000 error is equally hassle-free, to my mind it does shed some light on the nature of the runtime_flags.
It just might be the case that errors related to these flags (see the enum in the source code) may not really "break" the app. Some further information is required in order to be absolutely certain, but the above might be good enough to not be concerned about the app breaking.
P.S.: If you think this response is good enough, do mark it as an answer so I will have some feedback as well.
I am doing a java to c# transition, and need help.
in Visual Studio 2019 Pro, Android 9.0 (Pie), I am doing this example:
https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-a-jar
The goal is later to convert my java libs to c# for my big project.
I follow the instructions to the letter, and when I come to the part where I need to create an ImageView, there is the problem. Once I create the ImageView, it has an android:src field, something like this (auto generated):
android:src="#drawable/icon"
The problem here, is when I remove that field, in the VS designer, the ImageView disappears and it does not matter if I have the c# code or not, even when I set the srec to:""
Bellow is literally all the code in MainActivity:
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Com.Squareup.Picasso;
namespace App3
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
/***********************************************************************/
/**Picasso Code**/
ImageView imageView = FindViewById<ImageView>(Resource.Id.imageView1);
// Use the Picasso jar library to load and display this image:
Picasso.With(this)
.Load("http://i.imgur.com/DvpvklR.jpg")
.Into(imageView);
/**End Ff Picasso Code**/
/***********************************************************************/
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:src="#drawable/icon" <!-- this line -->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
</LinearLayout>
The app does nothing, and in the emulator, the ImageView is empty.
And there is no error, or anything.
If you need anything more, please let me know.
I hope you can help me, if not, thank you for your time.
Edit 1:
It seems, the problem lies in the C# code.
If I add the android:src field, it still does not show up on the emulator, but when I remove the code (the Picasso code) than the image(drawable/icon) shows. Still no error!!
try this
<ImageView
android:src="#drawable/icon" <!-- this line -->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="50px"
android:minHeight="50px"
android:id="#+id/imageView1" />
I'm trying to add ActionBar-PushToRefresh to my project. I've followed the instructions from Chris Banes Github there: Github ActionBar-PullToRefresh
Here is my view from which I want to enable the PullToRefresh feature:
<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ptr_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your content, here we're using a ScrollView -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="PULLTOREFRESH THE VIEW"
android:id="#+id/textView1" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout>
And here is my Activity to display the view:
package com.Test.pulltorefresh;
import android.app.Activity;
import android.os.Bundle;
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.Options;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;
public class MainActivity extends Activity {
private PullToRefreshLayout mPullToRefreshLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Now find the PullToRefreshLayout to setup
mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout);
// Now setup the PullToRefreshLayout
ActionBarPullToRefresh.from(this)
// Mark All Children as pullable
.allChildrenArePullable()
// Set the OnRefreshListener
//.listener(this)
// Finally commit the setup to our PullToRefreshLayout
.setup(mPullToRefreshLayout);
}
}
When I launch my app, I got the blank view but nothing happens when I'm trying to PushToRefresh my view. Can someone show me how to fix it, I know that I've missed something. Thanks.
I may be a bit partial but...
you could consider using this
Maybe you have already achieved the functionality, but in the code above, you have commented out the line which defines the action on pulling the view.
//.listener(this)
You should uncomment this line and define the listener method, which should be called when the view is pulled.
package com.example.one;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
Button button;
TextView txt1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton(){
button=(Button)findViewById(R.id.button1);//error line of code
txt1=(TextView)findViewById(R.id.txt);//error line of code
button.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
txt1.setText("hello");
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I have marked the error code of lines but unable to resolve
the .xml is
<EditText
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:layout_marginTop="26dp"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txt"
android:layout_below="#+id/txt"
android:layout_marginLeft="18dp"
android:layout_marginTop="110dp"
android:text="Button -MYBUT" />
I just want to add a button and a textview in my app beacuse I'm a beginner Android Developer so unable to resolve my issue thanks in advance
Try to use findViewById after you inflate your menu. You are trying to find an element in a view that has not yet be attached to the activity.
This is just fine, check your imports. In android are 2 types of R present.
- R Generated, by your project builder
- R brought by android sdk
I guess that you imported R from android SDK, not generated by your project. That's why eclipse yells with errors at you.
The other situation is, that, the findViewById() method called OnCreateOptionsMenu() callback is trying to reach view that has not been created yet, and returns null.
EDIT. Problems with R might be also associated with weird, not visible and hard to find mistakes in your xml files. When you make huge mistake in some of your xml files, builder returns error and R will not be generated. But in some cases, builder cant find any of your mistakes, but is not generating new R class - this causes your R to be out of date.
I just want to know that about the explanation of this line
but = (Button) findViewById(R.id.but);
findViewById(Id) returns a View and you have to cast that View to whatever UI element you are using.
In order for findViewById(Id) to return a View, you have to assign an Id to each UI element (if you want to use it in java):
<Button
android:id="#+id/myButtonId"
[...]
/>
Now you can do this:
but = (Button) findViewById(R.id.myButtonId);
You should also use the onCreate() method to initialize your UI elements, and not onCreateOptionsMenu().
Eclipse is a Curse try to not use it guys I Prefer NetBeans I love NetBeans so much Hats off for NetBeans!
The Answer of my own Question:
it was a real time fault of my eclipse (a curse) not my fault. The Solution is to restart the IDE or to press the Save All from File Menu of IDE
Visit: https://stackoverflow.com/a/7453201/2277645
My application has a spinning wheel for the initial app load. Works fine upto android 3.0 honeycomb. But in ICS 4.0 its broken. Its a simple spinning wheel animation. In ICS this wheel is spinning around a point near its circumference instead of the center point. This gives a visual impression like a wobbling wheel instead of a consistent spinning wheel. Here is the code
Layout:
<ImageView
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/spinner_white_48"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
/>
spinner_animation.xml
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="1200">
</rotate>
Java File (Activity)
Animation rotateSpinner = AnimationUtils.loadAnimation(this,R.anim.spinner_animation);
rotateSpinner.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
});
findViewById(R.id.spinner).startAnimation(rotateSpinner);
NOTE: The app wont even start on 4.0.2(Samsung Galaxy). But shows this distorted animation in 4.0.3 app app works fine(Nexus S).
Any help is appreciated. Thanks in advance
If by "wobbling" you mean that it appears to be revolving around something other than its center point, then this is a known bug.
Until there is a better fix, you can use:
RotateAnimation rotation;
if(Integer.parseInt(Build.VERSION.SDK) >=15){
rotation = new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.25f,Animation.RELATIVE_TO_SELF,0.25f);
}else{
rotation = new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
}
Check the layout settings. I have a feeling if you just drop the same view in a simple LinearLayout, it will work OK again. It appears you're in a RelativeLayout and I have a feeling the layout_centerHorizontal or layout_alignParentTop are giving you grief.
You should to add in your manifest this:
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true"/>