[android-beginners] Re: Problem with SQLite database, accessing the table
It looks to me like your program tries to fetch from the options table before it has been created. On May 7, 2:28 am, "mic.ger...@gmail.com" wrote: > Hi all, > I am developing an application that need a database (store username > and password) and when I try to access to it I obtain those errors in > the logCat : > > 05-07 09:02:17.194: ERROR/AndroidRuntime(520): Uncaught handler: > thread main exiting due to uncaught exception > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): > android.database.sqlite.SQLiteException: no such table: options: , > while compiling: SELECT DISTINCT _id, title, body FROM options WHERE > _id=0 > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteProgram.native_compile(Native Method) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:59) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:48) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteDirectCursorDriver.query > (SQLiteDirectCursorDriver.java:49) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteDatabase.rawQueryWithFactory > (SQLiteDatabase.java:1017) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteDatabase.queryWithFactory > (SQLiteDatabase.java:905) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:863) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > com.android.application.MonkeySMS.OptionDb.fetchOption(OptionDb.java: > 84) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > com.android.application.MonkeySMS.Option$1.onClick(Option.java:70) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.View.performClick(View.java:2129) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.View.onTouchEvent(View.java:3543) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.widget.TextView.onTouchEvent(TextView.java:4664) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.View.dispatchTouchEvent(View.java:3198) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > com.android.internal.policy.impl.PhoneWindow > $DecorView.superDispatchTouchEvent(PhoneWindow.java:1593) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent > (PhoneWindow.java:1089) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.app.Activity.dispatchTouchEvent(Activity.java:1871) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > com.android.internal.policy.impl.PhoneWindow > $DecorView.dispatchTouchEvent(PhoneWindow.java:1577) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.view.ViewRoot.handleMessage(ViewRoot.java:1140) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.os.Handler.dispatchMessage(Handler.java:88) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.os.Looper.loop(Looper.java:123) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > android.app.ActivityThread.main(ActivityThread.java:3739) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > java.lang.reflect.Method.invokeNative(Native Method) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > java.lang.reflect.Method.invoke(Method.java:515) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > (ZygoteInit.java:739) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) > 05-07 09:02:17.213: ERROR/AndroidRuntime(520): at > dalvik.system.NativeStart.main(Native Method) > > The problem appends when the program arrives at this line in my > program : > > if(mOptionDb.fetchOption(0)==null && mOptionDb.fetchOption(1)==null){ > mOptionDb.createOption(titleDb0, > txtUsername.toString > ()); > mOptionDb.createOption(titleDb1, > txtPassword.toString > ()); > } > > mOptionDb is an Option
[android-beginners] Re: how to get the string from a listview item
Try using Cursor instead of SQLiteCursor. On Apr 27, 11:11 pm, Kent Yip wrote: > Thx Glen the textview works great, but the SQLiteCursor doesn't work. > > On Mon, Apr 27, 2009 at 10:47 PM, Glen Humphrey > > wrote: > > > You could also do something like this in your onListItemClick. > > > SQLiteCursor cursor = (SQLiteCursor) l.getItemAtPosition > > (position); > > String title = cursor.getString(cursor.getColumnIndexOrThrow > > (RingtoneManager.EXTRA_RINGTONE_TITLE)); > > > On Apr 27, 10:26 pm, Glen Humphrey > > wrote: > > > Try something like this in your onListItemClick. > > > > TextView textView = (TextView) v.findViewById(R.id.title); > > > String text = textView.getText().toString(); > > > > On Apr 27, 8:14 pm, Kent Yip wrote: > > > > > i have a method that fill the list with items > > > > > // Depending on param, this method will display the list > > > > public void fillData( RingtoneManager rm, int type ) { > > > > // Set all type of sounds; notification, ringtone, alarm > > > > rm.setType( type ); > > > > c = rm.getCursor(); > > > > > startManagingCursor( c ); > > > > > String[] from = new String[] { > > RingtoneManager.EXTRA_RINGTONE_TITLE}; > > > > > int[] to = new int[] { R.id.title }; > > > > > SimpleCursorAdapter rt = > > > > new SimpleCursorAdapter( this, R.layout.ringtones_row, c, > > from, > > > > to ); > > > > setListAdapter( rt ); > > > > > }// end fillData() method > > > > > when i select an item i want to be able to display the ringtone's title > > or > > > > play the ringtone but i am having trouble doing so. > > > > > this get call when item is clicked > > > > > // Plays ringtone when cliking on the list item > > > > @Override > > > > public void onListItemClick(ListView l, View v, int position, long > > id) { > > > > super.onListItemClick(l, v, position, id); > > > > > // play the ringtone selected or get text/string from listview > > > > > Toast.makeText( this, text, Toast.LENGTH_SHORT ).show(); > > > > > }// end onListItemClick() method > > > > > i tried this: l.getItemAtPosition( position ) > > > > > that return an object data. but i have no clues as to what i could use > > to > > > > extract string title from it. > > > > > I use toString() to get and idea what i am accessing and it's a > > > > com.android.internal.sortcur...@12345678 > > > > > please help, much appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: how to get the string from a listview item
You could also do something like this in your onListItemClick. SQLiteCursor cursor = (SQLiteCursor) l.getItemAtPosition (position); String title = cursor.getString(cursor.getColumnIndexOrThrow (RingtoneManager.EXTRA_RINGTONE_TITLE)); On Apr 27, 10:26 pm, Glen Humphrey wrote: > Try something like this in your onListItemClick. > > TextView textView = (TextView) v.findViewById(R.id.title); > String text = textView.getText().toString(); > > On Apr 27, 8:14 pm, Kent Yip wrote: > > > i have a method that fill the list with items > > > // Depending on param, this method will display the list > > public void fillData( RingtoneManager rm, int type ) { > > // Set all type of sounds; notification, ringtone, alarm > > rm.setType( type ); > > c = rm.getCursor(); > > > startManagingCursor( c ); > > > String[] from = new String[] { > > RingtoneManager.EXTRA_RINGTONE_TITLE}; > > > int[] to = new int[] { R.id.title }; > > > SimpleCursorAdapter rt = > > new SimpleCursorAdapter( this, R.layout.ringtones_row, c, from, > > to ); > > setListAdapter( rt ); > > > }// end fillData() method > > > when i select an item i want to be able to display the ringtone's title or > > play the ringtone but i am having trouble doing so. > > > this get call when item is clicked > > > // Plays ringtone when cliking on the list item > > @Override > > public void onListItemClick(ListView l, View v, int position, long id) { > > super.onListItemClick(l, v, position, id); > > > // play the ringtone selected or get text/string from listview > > > Toast.makeText( this, text, Toast.LENGTH_SHORT ).show(); > > > }// end onListItemClick() method > > > i tried this: l.getItemAtPosition( position ) > > > that return an object data. but i have no clues as to what i could use to > > extract string title from it. > > > I use toString() to get and idea what i am accessing and it's a > > com.android.internal.sortcur...@12345678 > > > please help, much appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: how to get the string from a listview item
Try something like this in your onListItemClick. TextView textView = (TextView) v.findViewById(R.id.title); String text = textView.getText().toString(); On Apr 27, 8:14 pm, Kent Yip wrote: > i have a method that fill the list with items > > // Depending on param, this method will display the list > public void fillData( RingtoneManager rm, int type ) { > // Set all type of sounds; notification, ringtone, alarm > rm.setType( type ); > c = rm.getCursor(); > > startManagingCursor( c ); > > String[] from = new String[] { RingtoneManager.EXTRA_RINGTONE_TITLE}; > > int[] to = new int[] { R.id.title }; > > SimpleCursorAdapter rt = > new SimpleCursorAdapter( this, R.layout.ringtones_row, c, from, > to ); > setListAdapter( rt ); > > }// end fillData() method > > when i select an item i want to be able to display the ringtone's title or > play the ringtone but i am having trouble doing so. > > this get call when item is clicked > > // Plays ringtone when cliking on the list item > @Override > public void onListItemClick(ListView l, View v, int position, long id) { > super.onListItemClick(l, v, position, id); > > // play the ringtone selected or get text/string from listview > > Toast.makeText( this, text, Toast.LENGTH_SHORT ).show(); > > }// end onListItemClick() method > > i tried this: l.getItemAtPosition( position ) > > that return an object data. but i have no clues as to what i could use to > extract string title from it. > > I use toString() to get and idea what i am accessing and it's a > com.android.internal.sortcur...@12345678 > > please help, much appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Spinner won't work with ArrayAdapter in one project but will in another
It would help if we could see the problem code. On Apr 3, 9:12 am, Stu wrote: > Hi, > > I've been developing a quick little application for the last few days > and I've encountered some problems trying to get my spinner to display > a list of numbers that I have stored in an array resource. > > Basically I'm copying the Hello, Spinner example > onhttp://developer.android.com/guide/tutorials/views/hello-spinner.html > > If I copy that exactly then I get a spinner with a list of planets and > it works fine. If I alter the values to reference my own data then I > just get the prompt with a blank line underneath. > > Does it matter what data type is stored in the array? I only have > digits in mine, but I couldn't get it to work when I wrote the numbers > out (one, two, etc.). > > Does it matter that my layout uses TableLayout instead of > LinearLayout? > > Any ideas/suggestions? > > I'm using the latest SDK, and an up-to-date version of Eclipse, in > case it makes any difference. > > Thanks a lot, > Stuart. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: ListView focus problem
Try setting the width on the li_cht_text TextView to fill_parent. On Feb 3, 4:53 pm, Selmi wrote: > thanks a lot, i knew i had to do something stupid. this helped > partially, now text turns to black and is readable when focused > > but it didn't solved 2nd problem - when i make my own adapter and then > click on item then there is not orange flash on it. instead text > temporarily changes color to black (becomes unreadable because of > black background). i guess i must set something special for its > TextView to make it work? just for curiosity i went through listview > apidemos, especially List4, but didn't found anything special to > enable/disable > > my listview definition now looks like this: > > android:id="@android:id/list" > android:layout_width="fill_parent" > android:layout_height="0px" > android:layout_weight="1" > android:drawSelectorOnTop="false" > /> > > and its items: > > > http://schemas.android.com/apk/res/ > android" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > > > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:orientation="horizontal" > > > android:id="@+id/li_cht_checkbox" > android:layout_width="wrap_content" > android:layout_height="wrap_content" > android:layout_weight="0" > /> > android:id="@+id/li_cht_text" > android:layout_width="0px" > android:layout_height="wrap_content" > android:layout_weight="1" > android:singleLine="true" > > android:textAppearance="?android:attr/textAppearanceLarge" > /> > > > > On 4. Feb, 00:34 h., Romain Guy wrote: > > > Make sure you haven't set the selector to be drawn on top of the list items. > > > On Tue, Feb 3, 2009 at 3:31 PM, Selmi wrote: > > > > hi > > > > its probably extremely stupid question, but i can't move with it and > > > when i searched i didn't found anything relevant... > > > > problem: > > > > if you look to any listview api demos from samples you will see that > > > 1) when orange focus is over any item in list then its text changes to > > > black automatically > > > 2) when you click on any item it flashes with orange > > > > if you look to these listview api demos you will see there is no > > > additional code, just setting of adapter and some data. > > > > but when i use SimpleCursorAdapter with > > > android.R.layout.simple_list_item_1 in my application then if i scroll > > > list then this orange overlay hides text under it...all i see is > > > orange rectangle. why text under it doesn't change to black > > > > and if i use my own ListAdapter based on SimpleCursorAdapter then i > > > will not get this orange flash when item is clicked on. > > > > why i have no idea what is wrong, how come that code copied from > > > api demo to my code starts to behave differently? in xml file i don't > > > have anything special set for listview, just its dimensions are not > > > fill_parent but based on weight=1. > > > -- > > Romain Guy > > Android framework engineer > > romain...@android.com > > > Note: please don't send private questions to me, as I don't have time > > to provide private support. All such questions should be posted on > > public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
android-beginners@googlegroups.com
What does it say is wrong? On Apr 1, 12:07 am, Allan Ai wrote: > Why I cann`t run the following case? It says there are sth. wrong at > "onCreateOptionsMenu","onOptionsItemSelected"&"onPrepareOptionsMenu" . > > package com.demo.menu; > > import android.app.Activity; > import android.os.Bundle; > > public class MenuDemo extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > } > > @Override > public boolean onCreateOptionsMenu(Menu menu) { > super.onCreateOptionsMenu(menu); > menu.add(0,0,0,"1"); > menu.add(0,1,0,"2"); > menu.add(0,2,0,"3"); > menu.add(0,3,0,"4"); > menu.add(0,4,0,"5"); > return true; > } > > �...@override > public boolean onOptionsItemSelected(MenuItem item) { > super.onOptionsItemSelected(item); > TextView view = (TextView) findViewById(R.id.text_view); > switch (item.getItemId()) { > case 0: > view.setText("This is"+item.getTitle()); > break; > case 1: > view.setText("This is"+item.getTitle()); > break; > default: > view.setText("Debug."); > break; > } > return false; > } > > �...@override > public boolean onPrepareOptionsMenu(Menu menu) { > return super.onPrepareOptionsMenu(menu); > } > > } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Having Problems with Layout
Try this. android:orientation="vertical" On Apr 1, 8:57 am, Mike Wolfson wrote: > You could: > - Use a different layout (grid perhaps), which would allow you to > define your layout more directly > - set specific width values (instead of fill_parent) which would force > the layout you want. > > Not sure what might be happenning with this layout (not able to mess > with it at work), but this should get you past your problem. > > On Mar 30, 3:58 pm, rch wrote: > > > I am trYing to define a Layout which is a very simple Linear Layout > > that has a TextView and ListView. > > My activity is a ListActivity. I am trying out few things on top of > > the Notepad sampleApp. The problem I am facing is TextView and > > ListView are displayed in two columns. I want them displayed one > > below the other. I am not sure what mistake I am making. > > > > > http://schemas.android.com/apk/res/ > > android" > > android:layout_width="wrap_content" > > android:layout_height="wrap_content" > > android:orientation="horizontal"> > > > > android:layout_width="fill_parent" > > android:layout_height="wrap_content" > > android:text="test test" > > /> > > > android:layout_width="fill_parent" > > android:layout_height="wrap_content" > > /> > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Adding submenus in XML
In a menu XML layout, there are three valid elements: , and . The item and group elements must be children of a menu, but item elements may also be the children of a group, and another menu element may be the child of an item (to create a Submenu). Of course, the root node of any file must be a menu element. On Mar 30, 7:14 pm, suzannea wrote: > Does anyone have an example of adding a submenu to an options menu in > XML? I'm interested in doing something like this Java example (from > the Google developer guide, Creating Menus): > > public boolean onCreateOptionsMenu(Menu menu) { > boolean result = super.onCreateOptionsMenu(menu); > > SubMenu fileMenu = menu.addSubMenu("File"); > SubMenu editMenu = menu.addSubMenu("Edit"); > fileMenu.add("new"); > fileMenu.add("open"); > fileMenu.add("save"); > editMenu.add("undo"); > editMenu.add("redo"); > > return result; > > } > > However, I designed my options menu in XML, using the visual layout > editor. I tried putting several items within a group, like this: > > android:menuCategory="container" android:id="@+id/update_group"> > > > > > But instead of getting a submenu, I got additional items on the > options menu, which created an extended menu. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Editable to numeric - how to convert
You can do this. float weight = Float.valueOf(txt_weight.getText().toString()); or this double weight = Double.valueOf(txt_weight.getText().toString()); On Mar 30, 8:52 pm, Kaiwan wrote: > Greetings All, > > Am an Android app dev newbie, so pl bear with this (possibly) stupid > question. > (Actually i did post it last night in reply to a similar qs but it > does not seem to show up, so am re-posting as a new thread). > > Am developing an app, and a relatively small issue is driving me > nuts. > The app has an EditText widget. The user enters his/her weight in this > control. So lets say the user enters "65.5" (kg). I can retrieve this > value as a string (using txt_weight.getText().toString(); ). > But, I want to use it in an arithmetic expression, hence I require to > interpret it as a float. > How exactly do I do this?? > > Appreciate your help! > TIA, > kaiwan. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Setting Single Choice Dialog Checked Item
I found that if you do something like this it works almost identically to the magic number method. protected Dialog onCreateDialog(int id) { super.onCreateDialog(id); LayoutInflater factory = LayoutInflater.from(this); final View dialogView = factory.inflate (R.layout.your_dialog_layout, null); final ListView listView = (ListView) dialogView.findViewById (R.id.your_list); ArrayAdapter typeAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_single_choice, dialogItems); listView.setAdapter(typeAdapter); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return new AlertDialog.Builder(Learn1.this) .setTitle(R.string.input_required) .setView(dialogView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }) .create(); } protected void onPrepareDialog(int id, Dialog dialog) { super.onPrepareDialog(id, dialog); AlertDialog ad = (AlertDialog) dialog; ListView lv = (ListView) ad.findViewById(R.id.your_list); lv.clearChoices(); lv.setItemChecked(0, true); lv.setSelection(0); return; } static final String[] dialogItems = new String[] { "Map", "Satellite", "Traffic", "Street view" }; On Mar 28, 1:12 pm, Brian wrote: > Ok, selecting through the radiogroup works. I was expecting a > "setChecked" method, and just missed "checked". > Final version of onPrepareDialog(): > > RadioGroup rg = (RadioGroup) dialog.findViewById > (R.id.savecancelgroup); > rg.check(R.id.save); > > Thanks for the help. > > P.S. Using 16908667 was more fun... > > On Mar 28, 3:57 pm, Mark Murphy wrote: > > > Brian wrote: > > > I'm setting an individual RadioButton. Is that the right way to > > > select? > > > That should work. There's a corresponding method on RadioGroup. > > > > I have no idea if inflating from xml is the best way to instantiate a > > > view, it's just what popped in mind. > > > It's perfectly fine. You'll do this sort of thing in elaborate ListViews > > all the time, to create the rows the way you want 'em. > > > -- > > Mark Murphy (a Commons > > Guy)http://commonsware.com|http://twitter.com/commonsguy > > > _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Setting Single Choice Dialog Checked Item
I set a breakpoint in onPrepareDialog and looked at the dialog object. It contained a field called mAlert which contained a listview called mListVIew and that listview had a field called mId which had a value of 16908667. I then tried using that value in the findViewById method. It didn't work though until I cast the dialog as an AlertDialog. On Mar 28, 9:53 am, Brian wrote: > Ya, so how did you conjure up 16908667? > > In trying to debug this, I looked at the various android.R.id.* values > to see if I could see something else that makes sense, but didn't see > anything. If 16908667 is undocumented, where did you find it? By > spelunking through the source? > > Thanks. > > On Mar 28, 11:27 am, Glen Humphrey > wrote: > > > Every view in Android has an id number assigned to it. > > When you put android.R.id.button1 for example that is a constant that > > defines the number 16908313. > > The number 16908667 does not seem to have a constant defined for it in > > the SDK. > > This means that this number could be possibly be changed in a future > > version of the SDK > > and would break your program. I don't know why they have decided not > > to include that number. > > > You can see the defined constants at this link. > > >http://developer.android.com/reference/android/R.id.html#button1 > > > On Mar 28, 5:51 am, Brian wrote: > > > > Yes, that did work, thanks much. > > > > What does that magic number represent? > > > > On Mar 28, 2:54 am, Glen Humphrey wrote: > > > > > I also had to do one of the following to get it to work correctly. > > > > > if (!lv.isItemChecked(0)) { > > > > lv.setItemChecked(0, true); > > > > } > > > > > or > > > > > lv.clearChoices(); > > > > lv.setItemChecked(0, true); > > > > > On Mar 27, 11:17 pm, Glen Humphrey > > > > wrote: > > > > > > This seems to work for me. I have not been able to find a constant in > > > > > the SDK for 16908667. I will keep looking. > > > > > > AlertDialog ad = (AlertDialog) d; > > > > > ListView lv = (ListView) ad.findViewById(16908667); > > > > > lv.setItemChecked(0, true); > > > > > > On Mar 27, 6:15 pm, Brian wrote: > > > > > > > That returns null... Specifically: > > > > > > > protected void onPrepareDialog(int id, Dialog d){ > > > > > > super.onPrepareDialog(id, d); > > > > > > ListView lv = (ListView) d.findViewById(android.R.id.list); > > > > > > // lv is null > > > > > > ... > > > > > > > } > > > > > > > The dialog is created by: > > > > > > new AlertDialog.Builder(...) > > > > > > .setIcon(...) > > > > > > .setTitle(...) > > > > > > .setSingleChoiceItems(R.array.dialog_items, 0, new > > > > > > DialogInterface.OnClickListener() { > > > > > > public void onClick(DialogInterface dialog, int > > > > > > whichButton) { > > > > > > ... > > > > > > } > > > > > > }) > > > > > > more stuff > > > > > > .create(); > > > > > > > The dialog is shown by a call to: showDialog(1); > > > > > > > On Mar 27, 6:58 pm, Glen Humphrey > > > > > > wrote: > > > > > > > > I think you do something like this in the onPrepareDialog method. > > > > > > > > ListView listView = (ListView) > > > > > > > dialog.findViewById(android.R.id.list); > > > > > > > listView.setItemChecked(0, true); > > > > > > > > On Mar 27, 9:42 am, Brian wrote: > > > > > > > > > How do you set the checked item of a single choice dialog, > > > > > > > > after the > > > > > > > > dialog has been created? > > > > > > > > Subsequent calls to showDialog() seem to remember and display > > > > > > > > the > > > > > > > > user's last checked item. I want to set the checked item > > > > > > > > myself, each > > > > > > > > time the dialog is displayed. > > > > > > > > > Is there some way to set the selected item in onPrepareDialog() > > > > > > > > or > > > > > > > > elsewhere? > > > > > > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Setting Single Choice Dialog Checked Item
Every view in Android has an id number assigned to it. When you put android.R.id.button1 for example that is a constant that defines the number 16908313. The number 16908667 does not seem to have a constant defined for it in the SDK. This means that this number could be possibly be changed in a future version of the SDK and would break your program. I don't know why they have decided not to include that number. You can see the defined constants at this link. http://developer.android.com/reference/android/R.id.html#button1 On Mar 28, 5:51 am, Brian wrote: > Yes, that did work, thanks much. > > What does that magic number represent? > > On Mar 28, 2:54 am, Glen Humphrey wrote: > > > I also had to do one of the following to get it to work correctly. > > > if (!lv.isItemChecked(0)) { > > lv.setItemChecked(0, true); > > } > > > or > > > lv.clearChoices(); > > lv.setItemChecked(0, true); > > > On Mar 27, 11:17 pm, Glen Humphrey > > wrote: > > > > This seems to work for me. I have not been able to find a constant in > > > the SDK for 16908667. I will keep looking. > > > > AlertDialog ad = (AlertDialog) d; > > > ListView lv = (ListView) ad.findViewById(16908667); > > > lv.setItemChecked(0, true); > > > > On Mar 27, 6:15 pm, Brian wrote: > > > > > That returns null... Specifically: > > > > > protected void onPrepareDialog(int id, Dialog d){ > > > > super.onPrepareDialog(id, d); > > > > ListView lv = (ListView) d.findViewById(android.R.id.list); > > > > // lv is null > > > > ... > > > > > } > > > > > The dialog is created by: > > > > new AlertDialog.Builder(...) > > > > .setIcon(...) > > > > .setTitle(...) > > > > .setSingleChoiceItems(R.array.dialog_items, 0, new > > > > DialogInterface.OnClickListener() { > > > > public void onClick(DialogInterface dialog, int > > > > whichButton) { > > > > ... > > > > } > > > > }) > > > > more stuff > > > > .create(); > > > > > The dialog is shown by a call to: showDialog(1); > > > > > On Mar 27, 6:58 pm, Glen Humphrey wrote: > > > > > > I think you do something like this in the onPrepareDialog method. > > > > > > ListView listView = (ListView) dialog.findViewById(android.R.id.list); > > > > > listView.setItemChecked(0, true); > > > > > > On Mar 27, 9:42 am, Brian wrote: > > > > > > > How do you set the checked item of a single choice dialog, after the > > > > > > dialog has been created? > > > > > > Subsequent calls to showDialog() seem to remember and display the > > > > > > user's last checked item. I want to set the checked item myself, > > > > > > each > > > > > > time the dialog is displayed. > > > > > > > Is there some way to set the selected item in onPrepareDialog() or > > > > > > elsewhere? > > > > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Setting Single Choice Dialog Checked Item
I also had to do one of the following to get it to work correctly. if (!lv.isItemChecked(0)) { lv.setItemChecked(0, true); } or lv.clearChoices(); lv.setItemChecked(0, true); On Mar 27, 11:17 pm, Glen Humphrey wrote: > This seems to work for me. I have not been able to find a constant in > the SDK for 16908667. I will keep looking. > > AlertDialog ad = (AlertDialog) d; > ListView lv = (ListView) ad.findViewById(16908667); > lv.setItemChecked(0, true); > > On Mar 27, 6:15 pm, Brian wrote: > > > That returns null... Specifically: > > > protected void onPrepareDialog(int id, Dialog d){ > > super.onPrepareDialog(id, d); > > ListView lv = (ListView) d.findViewById(android.R.id.list); > > // lv is null > > ... > > > } > > > The dialog is created by: > > new AlertDialog.Builder(...) > > .setIcon(...) > > .setTitle(...) > > .setSingleChoiceItems(R.array.dialog_items, 0, new > > DialogInterface.OnClickListener() { > > public void onClick(DialogInterface dialog, int > > whichButton) { > > ... > > } > > }) > > more stuff > > .create(); > > > The dialog is shown by a call to: showDialog(1); > > > On Mar 27, 6:58 pm, Glen Humphrey wrote: > > > > I think you do something like this in the onPrepareDialog method. > > > > ListView listView = (ListView) dialog.findViewById(android.R.id.list); > > > listView.setItemChecked(0, true); > > > > On Mar 27, 9:42 am, Brian wrote: > > > > > How do you set the checked item of a single choice dialog, after the > > > > dialog has been created? > > > > Subsequent calls to showDialog() seem to remember and display the > > > > user's last checked item. I want to set the checked item myself, each > > > > time the dialog is displayed. > > > > > Is there some way to set the selected item in onPrepareDialog() or > > > > elsewhere? > > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Setting Single Choice Dialog Checked Item
This seems to work for me. I have not been able to find a constant in the SDK for 16908667. I will keep looking. AlertDialog ad = (AlertDialog) d; ListView lv = (ListView) ad.findViewById(16908667); lv.setItemChecked(0, true); On Mar 27, 6:15 pm, Brian wrote: > That returns null... Specifically: > > protected void onPrepareDialog(int id, Dialog d){ > super.onPrepareDialog(id, d); > ListView lv = (ListView) d.findViewById(android.R.id.list); > // lv is null > ... > > } > > The dialog is created by: > new AlertDialog.Builder(...) > .setIcon(...) > .setTitle(...) > .setSingleChoiceItems(R.array.dialog_items, 0, new > DialogInterface.OnClickListener() { > public void onClick(DialogInterface dialog, int > whichButton) { > ... > } > }) > more stuff > .create(); > > The dialog is shown by a call to: showDialog(1); > > On Mar 27, 6:58 pm, Glen Humphrey wrote: > > > I think you do something like this in the onPrepareDialog method. > > > ListView listView = (ListView) dialog.findViewById(android.R.id.list); > > listView.setItemChecked(0, true); > > > On Mar 27, 9:42 am, Brian wrote: > > > > How do you set the checked item of a single choice dialog, after the > > > dialog has been created? > > > Subsequent calls to showDialog() seem to remember and display the > > > user's last checked item. I want to set the checked item myself, each > > > time the dialog is displayed. > > > > Is there some way to set the selected item in onPrepareDialog() or > > > elsewhere? > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Setting Single Choice Dialog Checked Item
I think you do something like this in the onPrepareDialog method. ListView listView = (ListView) dialog.findViewById(android.R.id.list); listView.setItemChecked(0, true); On Mar 27, 9:42 am, Brian wrote: > How do you set the checked item of a single choice dialog, after the > dialog has been created? > Subsequent calls to showDialog() seem to remember and display the > user's last checked item. I want to set the checked item myself, each > time the dialog is displayed. > > Is there some way to set the selected item in onPrepareDialog() or > elsewhere? > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: MapView - findViewById returns null
Try this. On Mar 18, 5:22 am, Francois Stephany wrote: > I cant get it work. > Do I need something between the setContentView() and findViewById() ? > > --- > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > mapView = (MapView) findViewById(R.id.mapview1); > -- > > id="@+id/mapview1" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:enabled="true" > android:clickable="true" > android:apiKey="super key"/> > --- > > On 18 mar, 12:50, PRATAP SOLAPUR wrote: > > > Add id to the map view.wat u r doing is wrong..do it like > > this > > > android: id="@+id/mapview1" > > android:layout_width="fill_parent" > > android:layout_height="fill_parent" > > android:enabled="true" > > android:clickable="true" > > android:apiKey="woaw this is my dev key"/> > > > then call.. > > findViewById(R.id.mapview1) > > > On Tue, Mar 17, 2009 at 11:33 PM, Francois Stephany < > > > tulipe.mouta...@gmail.com> wrote: > > > > Hi there, > > > > I'm new to Android development and encounter a small problem. I try to > > > retrieve a MapView object in the onCreate method but findViewById > > > always returns null. > > > Here's the code: > > > > public class MySuperNiceActivity extends MapActivity { > > > > protected MapView mapView; > > > > /** Called when the activity is first created. */ > > > �...@override > > > public void onCreate(Bundle savedInstanceState) { > > > super.onCreate(savedInstanceState); > > > setContentView(R.layout.main); > > > mapView = (MapView) findViewById(R.main.mapview1); > > > > > > // end > > > > -- > > > main.xml: > > > > > > > http://schemas.android.com/apk/res/ > > > android" > > > android:orientation="vertical" > > > android:layout_width="fill_parent" > > > android:layout_height="fill_parent"> > > > > > > id="@+main/mapview1" > > > android:layout_width="fill_parent" > > > android:layout_height="fill_parent" > > > android:enabled="true" > > > android:clickable="true" > > > android:apiKey="woaw this is my dev key"/> > > > > > > > --- > > > > The map is displayed but the mapView instance variable stays null. > > > I guess there's something about the id in the xml files but i dont see > > > what... > > > any pointers? > > > > Cheers, > > > > Francois --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: How to specify the length of the EditText in a Table row
set the following properties for both the EditText and the TextView widgets. android:layout_weight="1" android:layout_width="fill_parent" On Mar 18, 2:56 pm, frizzo wrote: > I have a TableLayout with a couple of TableRows. Inside a table row, > i have an EditText widget followed by a TextView widget. > > How can I make sure that each widget in the row takes equal width? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---