oncreate

Android Edittext: Get LineCount in an Activity's onCreate()

痴心易碎 提交于 2019-12-24 01:25:17
问题 How can I do getLineCount() of an Edittext in the onCreate() method of an activity, having changed the Edittext's text, like the following: @override public void onCreate(Bundle savedInstanceState){ myEditText.setText("EXAMPLE"); myEditText.getLineCount(); } Because the view has not been drawn yet getLineCount() will always return 0. Is there a way to get around this problem? Thanks! 回答1: Ugh, it's a problem with UI everywhere. You can use a Handler. You'll post a Runnable that will get the

Android onCreate Service called when Activity onDestroy called

五迷三道 提交于 2019-12-22 09:13:12
问题 I have an activity that starts a service. If I exit to home screen and then from the recent apps list manually close the activity, onCreate is called again in the service. So when the activity is destroyed, onCreate is called again (even though the service was running at the time onDestroy was called in the activity) I don't want onCreate in the service to be called again. I know its a possible duplication of this: Android service onCreate is called multiple times without calling onDestroy

Difference between getExtras(name).getString and getIntent().getStringExtra(name)

て烟熏妆下的殇ゞ 提交于 2019-12-22 05:01:20
问题 I have some error reports on my Android app, it's a Nullpointerexception in onCreate() in an Activity. The code that fails is getIntent().getExtras().getStringExtra("name"). (Nullpointerexception) That means that getExtras() is null somehow. I am sure that I am setting the intent extra on every place I am creating the intent. I can't recreate it on my emulator on device. I think it happened on my real device (but not while I was debugging) after I tried to open the app again, in the mean time

AlertDialog with spinner on start of activity

和自甴很熟 提交于 2019-12-22 00:18:33
问题 I am trying to create an AlertDialog with a spinner on the start of an activity. I have the following code within the activity's onCreate() method. AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alertDialog; Context mContext = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_dialog, (ViewGroup) findViewById(R.id.layout_root)); Spinner spinner =

Load Data setOnItemSelectedListener

China☆狼群 提交于 2019-12-20 06:28:19
问题 Problem: I load my class, the setOnItemSelectedListener function runs and sets variable wattage to a specific value, depending on what item was selected in the spinner. How can I prevent this from happening, how can I include a custom value for a variable wattage? Detail: I have a class called edit lighting. In this class all I want to do is load the data from the database. Currently when the light type spinner is selected, I associate a value with it. e.g. I pick CFL - wattage is then 26.

Android Sliding Drawer Open On Create

僤鯓⒐⒋嵵緔 提交于 2019-12-20 04:34:09
问题 I want to have a slider that is open when the app starts. It will be open with buttons and such and when the user closes it, there will be more buttons to access. Is this possible with a sliding drawer? What would I add to the onCreate() method? Thanks 回答1: XML Layout - In a basic LinearLayout: <SlidingDrawer android:id="@+id/slide" android:layout_width="match_parent" android:layout_height="wrap_content" android:content="@+id/content" android:handle="@+id/handle" android:orientation="vertical

OnCreate not called on Activity

家住魔仙堡 提交于 2019-12-18 07:38:27
问题 I've created AbstractActivity and an AbstractFormActivity to rid of some boilerplate code, their content may be irrelevant to the question, but I will post it anyway, maybe I misunterstood something so, there they are: public abstract class AbstractActivity extends ActionBarActivity { protected ObjectGraph graph; @Inject public Bus bus; @Inject public App app; @Override public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { super.onCreate(savedInstanceState,

Detect First Run

北城余情 提交于 2019-12-18 05:24:14
问题 I am trying to detect if my app has been run before, by using this code: (This is in my default Android activity) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { Log.w("activity", "first time"); setContentView(R.layout.activity_clean_weather); } else { Log.w("activity", "second time"); setContentView(R.layout.activity_clean_weather); } } When I first run the app it says first time, when I run it a second time,

android - There is no default constructor for ArrayAdapter

蹲街弑〆低调 提交于 2019-12-18 05:09:07
问题 I m making adapter to adapt my book collection to be visible in list view. Issue is solved if I add super(context, position): public BookAdapter(Context context, int position, List <Book> updatedBooksList) { super(context, position); this.context = context; this.booksList = updatedBooksList ; } However, I want to know why I need this argument (int position) and call superclass constructor? protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Also, in the

What is a OnCreate method in android

家住魔仙堡 提交于 2019-12-17 15:29:19
问题 I am new to android trying to understand what the below method does public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // load the layout setContentView(R.layout.filters); } My research :: onCreate is used to start an activity super is used to call the parent class constructor setContentView is used to set the xml But what is this all together - onCreate(Bundle savedInstanceState) .... why did that bundle come there, what is it What is that super.onCreate