[android-developers] Re: adding style in xml breaks onClick events.
solved it!! if you use style=?sytleItem in a listview the context menu breaks, onclick still works. using style=?attr/styleItem fixes it. don't ask why, i figured it out by reading the android source and (LOT of) trial and error. On May 6, 7:34 pm, denov d...@syncopated.net wrote: the ? references a (custom) attribute of theme to allow you to switch themes in your activity. take a look athttp://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... On May 6, 8:52 am, Justin Anderson magouyaw...@gmail.com wrote: * style=?listItem* * * This line seems weird to me... If you take a look at this link I think you will find the problem:http://developer.android.com/guide/topics/ui/themes.html Shouldn't it be: style=@style/list_item_bl? *** * Thanks, Justin Anderson On Thu, May 5, 2011 at 5:11 PM, denov d...@syncopated.net wrote: style=?listItem -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] no option menu with touch only keyboard.
hey all, could somebody please clue me in to why i'm not getting context menu to show up with touch? it works fine if i use the keyboard. public class ViewTasks extends ListActivity implements View.OnCreateContextMenuListener { private static final String TAG = TT:ListActivity; private static final int ACTIVITY_ADD=1; private static final int ACTIVITY_EDIT=2; private static final int DELETE_ID = Menu.FIRST; private TaskDbAdapter _dbHelper; private Cursor _taskCursor; private SimpleDateFormat _listFormat = new SimpleDateFormat(MM-dd- yy); protected CharSequence[] _options; protected boolean[] _selections; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); _dbHelper = new TaskDbAdapter(this); try { _dbHelper.open(); } catch (SQLException e) { throw new RuntimeException(e); } _options = getResources().getStringArray(R.array.task_item); _selections = new boolean[_options.length]; for (int i = 0; i _selections.length; i++) { _selections[i] = true; } fillData(); registerForContextMenu(getListView()); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.general_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.add: Intent i = new Intent(this, TrackTask.class); startActivityForResult(i, ACTIVITY_ADD); return true; case R.id.export: exportData(); break; case R.id.filter: showDialog(0); break; } return super.onOptionsItemSelected(item); } @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn) { menu.add(0, DELETE_ID, 0, R.string.menu_delete_task); } @Override public boolean onContextItemSelected(MenuItem item) { switch(item.getItemId()) { case DELETE_ID: AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); _dbHelper.deleteTask(info.id); fillData(); return true; default: { return super.onContextItemSelected(item); } } } @Override protected Dialog onCreateDialog(int id) { return new AlertDialog.Builder(this) .setTitle(Filter) .setMultiChoiceItems(_options, _selections, new DialogSelectionClickHandler()) .setPositiveButton(OK, new DialogButtonClickHandler() ) .create(); } public class DialogSelectionClickHandler implements DialogInterface.OnMultiChoiceClickListener { public void onClick( DialogInterface dialog, int clicked, boolean selected ) { Log.d( TAG, _options[ clicked ] + selected: + selected ); } } public class DialogButtonClickHandler implements DialogInterface.OnClickListener { public void onClick( DialogInterface dialog, int clicked ) { switch(clicked) { case DialogInterface.BUTTON_POSITIVE: fillData(); break; } } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if(intent == null) return; Bundle extras = intent.getExtras(); switch(requestCode) { case ACTIVITY_EDIT: Long rowId = extras.getLong(TaskDbAdapter.KEY_ROWID); if (rowId != null) { String item = extras.getString(TaskDbAdapter.KEY_ITEM); String category = extras.getString(TaskDbAdapter.KEY_CATEGORY); String note = extras.getString(TaskDbAdapter.KEY_NOTE); long date = extras.getLong(TaskDbAdapter.KEY_DATE); _dbHelper.updateTask(rowId, item, category, date, note); } fillData(); break; case ACTIVITY_ADD: String item = extras.getString(TaskDbAdapter.KEY_ITEM); String category =
[android-developers] Re: adding style in xml breaks onClick events.
after some more playing around i've found my code works, but only if use the keyboard. no touch or mouse in emulator. anybody had a clue to where i've gone wrong?here's some updated code -- private void fillData() { ArrayListString names = new ArrayListString(); for (int i = 0; i _options.length; i++) { String item = (String) _options[i]; if (_selections[i]) names.add(item); } _taskCursor = _dbHelper.fetchTasksByName(names); startManagingCursor(_taskCursor); String[] from = new String[] { TaskDbAdapter.KEY_ITEM, TaskDbAdapter.KEY_CATEGORY, TaskDbAdapter.KEY_DATE }; int[] to = new int[] { R.id.category_entry, R.id.item_entry, R.id.date_completed }; ListAdapter listAdapter = new ListAdapter(this, R.layout.list_item, _taskCursor, from, to); getListView().setOnCreateContextMenuListener(this); setListAdapter(listAdapter); } final class ListAdapter extends SimpleCursorAdapter implements View.OnClickListener { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.list_item, parent, false); return view; } @Override public void bindView(View view, Context context, Cursor c) { TextView itemView = (TextView) view.findViewById(R.id.item_entry); TextView categoryView = (TextView) view.findViewById(R.id.category_entry); TextView dateView = (TextView) view.findViewById(R.id.date_completed); itemView.setText(c.getString(c.getColumnIndexOrThrow(TaskDbAdapter.KEY_ITEM))); itemView.setFocusable(false); itemView.setFocusableInTouchMode(false); categoryView.setText(c.getString(c.getColumnIndexOrThrow(TaskDbAdapter.KEY_CATEGORY))); dateView.setText(_listFormat.format(new Date(c.getLong(c.getColumnIndexOrThrow(TaskDbAdapter.KEY_DATE); view.setOnClickListener(this); // view.setOnCreateContextMenuListener(ViewTasks.this); // this works - kinda of.. with no menuInfo view.setTag(c.getPosition()); } . } On May 5, 4:11 pm, denov d...@syncopated.net wrote: when i add thestyleattribute for the my relativeLayout below itbreakstheonClickeventsin my activity. --- stylename=list_item_bl parent=text_large_bl item name=android:paddingRight4sp/item item name=android:paddingLeft4sp/item item name=android:background@drawable/list_item_bl/item item name=android:focusablefalse/item item name=android:focusableInTouchModefalse/item item name=android:clickabletrue/item /style ?xmlversion=1.0 encoding=utf-8? LinearLayout xmlns:android=http://schemas.android.com/apk/res/ android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent TextView android:id=@+id/TextView01 android:layout_height=wrap_content android:text=blah blah blah... blah blah android:textStyle=normal|bold android:gravity=center_vertical|center_horizontal android:layout_width=fill_parent / ListView android:id=@android:id/list android:layout_height=wrap_content android:layout_width=fill_parent / TextView android:id=@+id/android:empty android:layout_width=wrap_content android:layout_height=wrap_content android:text=@string/nothing / /LinearLayout ?xmlversion=1.0 encoding=utf-8? RelativeLayout xmlns:android=http://schemas.android.com/apk/res/ android android:layout_width=fill_parent android:layout_height=wrap_content android:orientation=horizontal android:id=@+id/list_item style=?listItem TextView android:id=@+id/item_entry android:layout_width=wrap_content android:layout_height=wrap_content android:gravity=left android:focusable=false android:focusableInTouchMode=false/ TextView android:id=@+id/category_entry android:layout_width=wrap_content android:layout_height=wrap_content android:layout_toRightOf=@id/item_entry android:gravity=right
[android-developers] Re: adding style in xml breaks onClick events.
the ? references a (custom) attribute of theme to allow you to switch themes in your activity. take a look at http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/styles.xml;h=c95ede77325740175c90d8de1504bc7fec4361a9;hb=HEAD On May 6, 8:52 am, Justin Anderson magouyaw...@gmail.com wrote: * style=?listItem* * * This line seems weird to me... If you take a look at this link I think you will find the problem:http://developer.android.com/guide/topics/ui/themes.html Shouldn't it be: style=@style/list_item_bl? *** * Thanks, Justin Anderson On Thu, May 5, 2011 at 5:11 PM, denov d...@syncopated.net wrote: style=?listItem -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] adding style in xml breaks onClick events.
when i add the style attribute for the my relativeLayout below it breaks the onClick events in my activity. --- style name=list_item_bl parent=text_large_bl item name=android:paddingRight4sp/item item name=android:paddingLeft4sp/item item name=android:background@drawable/list_item_bl/item item name=android:focusablefalse/item item name=android:focusableInTouchModefalse/item item name=android:clickabletrue/item /style ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=http://schemas.android.com/apk/res/ android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent TextView android:id=@+id/TextView01 android:layout_height=wrap_content android:text=blah blah blah... blah blah android:textStyle=normal|bold android:gravity=center_vertical|center_horizontal android:layout_width=fill_parent / ListView android:id=@android:id/list android:layout_height=wrap_content android:layout_width=fill_parent / TextView android:id=@+id/android:empty android:layout_width=wrap_content android:layout_height=wrap_content android:text=@string/nothing / /LinearLayout ?xml version=1.0 encoding=utf-8? RelativeLayout xmlns:android=http://schemas.android.com/apk/res/ android android:layout_width=fill_parent android:layout_height=wrap_content android:orientation=horizontal android:id=@+id/list_item style=?listItem TextView android:id=@+id/item_entry android:layout_width=wrap_content android:layout_height=wrap_content android:gravity=left android:focusable=false android:focusableInTouchMode=false/ TextView android:id=@+id/category_entry android:layout_width=wrap_content android:layout_height=wrap_content android:layout_toRightOf=@id/item_entry android:gravity=right android:paddingLeft=8sp android:focusable=false android:focusableInTouchMode=false/ TextView android:id=@+id/date_completed android:layout_width=wrap_content android:layout_height=wrap_content android:layout_alignParentRight=true android:gravity=right android:paddingLeft=4sp android:focusable=false android:focusableInTouchMode=false/ /RelativeLayout public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); fillData(); getListView().setOnCreateContextMenuListener(this); } private void fillData() { ArrayListString names = new ArrayListString(); for (int i = 0; i _options.length; i++) { String item = (String) _options[i]; if (_selections[i]) names.add(item); } _taskCursor = _dbHelper.fetchTasksByName(names); startManagingCursor(_taskCursor); String[] from = new String[] { TaskDbAdapter.KEY_ITEM, TaskDbAdapter.KEY_CATEGORY, TaskDbAdapter.KEY_DATE }; int[] to = new int[] { R.id.category_entry, R.id.item_entry, R.id.date_completed }; ListAdapter notesAdapter = new ListAdapter(this, R.layout.list_item, _taskCursor, from, to); //SimpleCursorAdapter notesAdapter = new SimpleCursorAdapter(this, R.layout.list_item, taskCursor, from, to) notesAdapter.setViewBinder(new ViewBinder() { public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) { if (aColumnIndex == 3) { Date createDate = new Date(aCursor.getLong(aColumnIndex)); TextView textView = (TextView) aView; textView.setText(listFormat.format(createDate)); return true; } return false; } }); setListAdapter(notesAdapter); } --- i wrote a custom ListAdapter to see that would solve my problem. i can catch the listOnClick this way (with a lot of extra work) but onCreateContextMenu never seems to get invoked. this seems really weird that applying a style would break event handling... -- You received this message because you are