Couldn't get the seekbar by findViewById

by Jeruliu » Sat, 29 May 2010 01:31:23 GMT


Sponsored Links
 I'm building a dialog including seekbar but i can't locate the seekbar
by findViewById, it only returns nullpoint.

My code:
Context mContext = this;
                LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
                View layout = inflater.inflate(R.layout.brightness,
                                               (ViewGroup)
findViewById(R.id.layout_root));

                builder = new AlertDialog.Builder(mContext);
                builder.setView(layout);
                builder.setTitle("Brightness");
                builder.setPositiveButton("Ok", new
DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int 
whichButton) {
/////////// The seekBar here is a null point however?
                                SeekBar seekBar = (SeekBar) 
findViewById(R.id.seekbar);
                                int progress = seekBar.getProgress();
                                Log.v(TAG, "=====++++ progress is : " + 
progress);
                        }
                });

And my layouy brightness.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
        android:id="@+id/layout_root" android:orientation="vertical"
        android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
        <ImageView android:id="@+id/brightness_level_icon"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:src="@drawable/
brightness_level_icon"
               />
        <SeekBar android:id="@+id/seekbar" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:max="255"
                android:progress="125" />
</LinearLayout>

Any hints from your expertshanks.

--



Couldn't get the seekbar by findViewById

by Mark Murphy » Sat, 29 May 2010 02:09:32 GMT


 


You are calling findViewById() on your activity. Your activity
presumably does not have a SeekBar named R.id.seekbar.

Try calling layout.findViewById(R.id.seekbar) instead.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books 

--


Sponsored Links


Couldn't get the seekbar by findViewById

by Jeruliu » Sat, 29 May 2010 11:34:15 GMT


 Wow, thanks Mark, you are absolutely not just a common guy!!!






--



Other Threads

1. App often crash with virtual keyboard.

Since cupcake we have a crash with one of our EditText widget when
using a virtual keyboard in landscape, it's random but happens often:

05-19 11:01:54.819: ERROR/AndroidRuntime(21788): Uncaught handler:
thread main exiting due to uncaught exception
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):
java.lang.IndexOutOfBoundsException: getChars (38 ... 0) has end
before start
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.text.SpannableStringBuilder.checkRange
(SpannableStringBuilder.java:935)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.text.SpannableStringBuilder.getChars
(SpannableStringBuilder.java:847)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.text.TextUtils.getChars(TextUtils.java:69)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.text.SpannableStringBuilder.<init>(SpannableStringBuilder.java:
59)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.text.SpannableStringBuilder.subSequence
(SpannableStringBuilder.java:839)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.widget.TextView.extractTextInternal(TextView.java:4405)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.widget.TextView.reportExtractedText(TextView.java:4443)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.widget.TextView.finishBatchEdit(TextView.java:4585)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.widget.TextView.endBatchEdit(TextView.java:4567)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
com.android.internal.widget.EditableInputConnection.endBatchEdit
(EditableInputConnection.java:54)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
com.android.internal.view.IInputConnectionWrapper.executeMessage
(IInputConnectionWrapper.java:334)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
com.android.internal.view.IInputConnectionWrapper
$MyHandler.handleMessage(IInputConnectionWrapper.java:57)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.os.Handler.dispatchMessage(Handler.java:99)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.os.Looper.loop(Looper.java:123)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
java.lang.reflect.Method.invokeNative(Native Method)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
java.lang.reflect.Method.invoke(Method.java:521)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
05-19 11:01:55.019: ERROR/AndroidRuntime(21788):     at
dalvik.system.NativeStart.main(Native Method)

I don't understand at all... The EditText is in a ViewFlipper with a
Gallery, and a ListView.
--~--~---------~--~----~------------~-------~--~----~

2. Buy 1 app get 4 copies free with M

http://www.computerworld.com/action/article.do?command=viewArticleBasic&taxonomyName=windows&articleId=9133186&taxonomyId=125&intsrc=kc_top

Al.

---

* Written an Android App? - List it at http://andappstore.com/ *

======
Funky Android Limited is registered in England & Wales with the 
company number  6741909. The registered head office is Kemp House, 
152-160 City Road, London,  EC1V 2NX, UK. 

The views expressed in this email are those of the author and not 
necessarily those of Funky Android Limited, it's associates, or it's 
subsidiaries. 



--~--~---------~--~----~------------~-------~--~----~

3. How to get the resource ID from android.content.res.Resources.Theme

4. ContentProvider returns always null

5. lock_fb_info

6. How to determine if application is running on the emulator?

7. Using glColor4x