[android-developers] Re: Integrate ImageButton with ListActivity failed - List no longer selectable.
Hi Chander, thanks for your help. I have added android:focusable=false to the layout xml file but the result appears to be the same. I thought this type of listActivity working with buttons etc is supposed to be straightforward. But I failed to find a working example so far. I am stucked here. On Jan 31, 8:22 am, Chander Pechetty cspeche...@gmail.com wrote: make sure your list item does not contains focusable children (like buttons, imageviews) setting android:focusable=false usually works for buttons and so on... On Jan 30, 2:42 pm, qmwestview qmwestv...@googlemail.com wrote: Hi, I have a workingListActivityclass. Each of the list item consists of an ImageView and a TextView. However, when I try to replace the ImageView withImageButton, The list becomes unselectable. The onListItemClick or any other function no longer get called when press a list item (Although the track ball can still focus a list item, but nothing more can be done). I have searched the forum and also the internet and failed to find any such working example, apart from one guy reporting a similar problem but with no answer. The following is my code: 1. The list_item.xml: ?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=?android:attr/listPreferredItemHeight ImageButton android:id=@+id/refresh android:layout_width=wrap_content android:layout_height=fill_parent android:layout_alignParentTop=true android:layout_alignParentBottom=true android:src=@drawable/refresh / TextView android:id=@+id/title android:layout_width=fill_parent android:layout_height=fill_parent android:layout_toRightOf=@id/refresh android:layout_alignParentBottom=true android:layout_alignParentRight=true android:singleLine=true/ /RelativeLayout 2. the MainListActivityclass: import android.app.Dialog; import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class TestListActivity extendsListActivityimplements Constants { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new EfficientAdapter(this)); } @Override protected void onListItemClick(ListView l, View v, int index, long id) { Log.i(, onListitemClick); } public boolean onContextItemSelected(MenuItem item) { Log.i(, onContextItemSelected); return false; } private class EfficientAdapter extends BaseAdapter implements Constants { private LayoutInflater layoutInflater; Context ctx; public EfficientAdapter(Context context) { // Cache the LayoutInflate to avoid asking for a new one each time. layoutInflater = LayoutInflater.from(context); ctx = context; } @Override public int getCount() { Log.i(, getCount); return SIZE; } @Override public Object getItem(int position) { Log.i(, getItem); return TBD; } @Override public long getItemId(int positin) { Log.i(, getItemId); return positin; } public void update(int position) { notifyDataSetChanged(); // triggers the view data to be refreshed! } /** * Make a view to hold each list item */ @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i(, getView); ViewHolder holder; if (convertView == null) { convertView = this.layoutInflater.inflate(R.layout.list_item, parent, false); holder = new ViewHolder(); holder.title = (TextView
[android-developers] Re: Integrate ImageButton with ListActivity failed - List no longer selectable.
Update: I found a way to intercept the key press, by just adding the following code into getView(final int position, View convertView, ViewGroup parent) method: convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.i( onClick :, (new Integer(position)).toString ()); } }); The problem with this approach is when pressing a list item, the list item no longer get highlighted. Anyone knows how to manually highlight a list item (suppose we know its position)? I have tried v.setSelected(true) but the effect appears to be not good. -- 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] Re: Integrate ImageButton with ListActivity failed - List no longer selectable.
Adding android:focusable=false does work with CheckBox (tested: just replace ImageButton with CheckBox in layout xml file). On Feb 1, 11:12 am, qmwestview qmwestv...@googlemail.com wrote: Hi Chander, thanks for your help. I have added android:focusable=false to the layout xml file but the result appears to be the same. I thought this type oflistActivityworking with buttons etc is supposed to be straightforward. But I failed to find a working example so far. I am stucked here. On Jan 31, 8:22 am, Chander Pechetty cspeche...@gmail.com wrote: make sure your list item does not contains focusable children (like buttons, imageviews) setting android:focusable=false usually works for buttons and so on... On Jan 30, 2:42 pm, qmwestview qmwestv...@googlemail.com wrote: Hi, I have a workingListActivityclass. Each of the list item consists of an ImageView and a TextView. However, when I try to replace the ImageView withImageButton, The list becomes unselectable. The onListItemClick or any other function no longer get called when press a list item (Although the track ball can still focus a list item, but nothing more can be done). I have searched the forum and also the internet and failed to find any such working example, apart from one guy reporting a similar problem but with no answer. The following is my code: 1. The list_item.xml: ?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=?android:attr/listPreferredItemHeight ImageButton android:id=@+id/refresh android:layout_width=wrap_content android:layout_height=fill_parent android:layout_alignParentTop=true android:layout_alignParentBottom=true android:src=@drawable/refresh / TextView android:id=@+id/title android:layout_width=fill_parent android:layout_height=fill_parent android:layout_toRightOf=@id/refresh android:layout_alignParentBottom=true android:layout_alignParentRight=true android:singleLine=true/ /RelativeLayout 2. the MainListActivityclass: import android.app.Dialog; import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class TestListActivity extendsListActivityimplements Constants { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new EfficientAdapter(this)); } @Override protected void onListItemClick(ListView l, View v, int index, long id) { Log.i(, onListitemClick); } public boolean onContextItemSelected(MenuItem item) { Log.i(, onContextItemSelected); return false; } private class EfficientAdapter extends BaseAdapter implements Constants { private LayoutInflater layoutInflater; Context ctx; public EfficientAdapter(Context context) { // Cache the LayoutInflate to avoid asking for a new one each time. layoutInflater = LayoutInflater.from(context); ctx = context; } @Override public int getCount() { Log.i(, getCount); return SIZE; } @Override public Object getItem(int position) { Log.i(, getItem); return TBD; } @Override public long getItemId(int positin) { Log.i(, getItemId); return positin; } public void update(int position) { notifyDataSetChanged(); // triggers the view data to be refreshed! } /** * Make a view to hold each list item */ @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i(, getView
[android-developers] Re: Integrate ImageButton with ListActivity failed - List no longer selectable.
Tried again and this time successful. Instead of doing it in xml file, do it in code does the trick: holder.imageButton.setFocusable(false); Problem solved! -- 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] Integrate ImageButton with ListActivity failed - List no longer selectable.
Hi, I have a working ListActivity class. Each of the list item consists of an ImageView and a TextView. However, when I try to replace the ImageView with ImageButton, The list becomes unselectable. The onListItemClick or any other function no longer get called when press a list item (Although the track ball can still focus a list item, but nothing more can be done). I have searched the forum and also the internet and failed to find any such working example, apart from one guy reporting a similar problem but with no answer. The following is my code: 1. The list_item.xml: ?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=?android:attr/listPreferredItemHeight ImageButton android:id=@+id/refresh android:layout_width=wrap_content android:layout_height=fill_parent android:layout_alignParentTop=true android:layout_alignParentBottom=true android:src=@drawable/refresh / TextView android:id=@+id/title android:layout_width=fill_parent android:layout_height=fill_parent android:layout_toRightOf=@id/refresh android:layout_alignParentBottom=true android:layout_alignParentRight=true android:singleLine=true/ /RelativeLayout 2. the Main ListActivity class: import android.app.Dialog; import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class TestListActivity extends ListActivity implements Constants { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new EfficientAdapter(this)); } @Override protected void onListItemClick(ListView l, View v, int index, long id) { Log.i(, onListitemClick); } public boolean onContextItemSelected(MenuItem item) { Log.i(, onContextItemSelected); return false; } private class EfficientAdapter extends BaseAdapter implements Constants { private LayoutInflater layoutInflater; Context ctx; public EfficientAdapter(Context context) { // Cache the LayoutInflate to avoid asking for a new one each time. layoutInflater = LayoutInflater.from(context); ctx = context; } @Override public int getCount() { Log.i(, getCount); return SIZE; } @Override public Object getItem(int position) { Log.i(, getItem); return TBD; } @Override public long getItemId(int positin) { Log.i(, getItemId); return positin; } public void update(int position) { notifyDataSetChanged(); // triggers the view data to be refreshed! } /** * Make a view to hold each list item */ @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i(, getView); ViewHolder holder; if (convertView == null) { convertView = this.layoutInflater.inflate(R.layout.list_item, parent, false); holder = new ViewHolder(); holder.title = (TextView) convertView.findViewById(R.id.title); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.title.setText(R.string.title); parent.focusableViewAvailable(convertView); // originally without this. Added for testing, still not working! return convertView; } private class ViewHolder { //ImageButton imageButton; TextView title; } } } Is there any way to make ListActivity working with ImageButton or this actually can not be achieved (iPhone can this)? Any help would be most
[android-developers] How to repeat Login dialog and progress dialog, coordinating with http thread
Hi there, I am having a problem about repeating Login dialog (an AlertDialog) and progress dialog, coordinating with http thread. I suppose repetitive Login dialog (if fail, continue) handling should be common and straightforward. I guess my approach must be wrong somewhere. I already spent 2 days on this and am desperate. So please help. The usecase is like this: I have a main activity. User starts the app, the main activity starts. Show a login dialog (generated by the main thread, i.e. from onCreate ()). The main thread then starts a wait_thread, which will wait for http to return data and check the data and decide what to do. After user input username/password and press login, a progress dialog starts. The progress dialog starts an http_thread to talk to the server and get replies. Once done, it will notify the waiting thread. If the user type in the right username password first time, the code works fine. But it always fail for 2nd time Login, i.e. When first login fail (wrong username/password), the wait_thread will generate 2nd Login dialog to let user repeat the login process. But after user hit the login on this 2nd Login dialog, the system always crashes. The exception here is: ERROR/AndroidRuntime(21880): Uncaught handler: thread main exiting due to uncaught exception ERROR/AndroidRuntime(21880): android.view.ViewRoot $CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. The followings are part of the code. ... public class Test extends Activity implements Constants,Runnable{ ... @Override public void onCreate(Bundle savedInstanceState) { ... showDialog(DIALOG_LOGIN); // startHttpWaitThread(); } private void startHttpWaitThread(){ try { Thread dialogThread = new Thread(this); dialogThread.start(); } catch(Exception e){ //showDialog(DIALOG_LOGIN); } } /* @Override public void onStart() { super.onStart(); } */ public void run(){ Looper.prepare(); try { synchronized(httpReplyData){ // httpReplyData holds all needed data returned from server httpReplyData.wait(); } } catch(Exception e) { e.printStackTrace(); } if (httpReplyData.getHttpResult()!=HTTP_REPLY_STATUS_CODE_OK_200) showDialog(DIALOG_LOGIN); Looper.loop(); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_LOGIN: return getLoginDialog(this);//, case DIALOG_LOGIN_PROGRESS: return new LoginProgressDialog (ctxForLoginProgressDialog);//} return null; } private Dialog getLoginDialog(Context ctx) {//, String name, String pwd){ ... dialogBuilder.setPositiveButton(R.string.login, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { networkService.startHttpThread (HTTP_REQUEST_LOGIN_INDEX, getUsername(), getPassword()); // networkService is the HTTP manager showDialog(DIALOG_LOGIN_PROGRESS); // startHttpWaitThread(); } }); return dialogBuilder.create(); } private class LoginProgressDialog extends ProgressDialog implements Constants{ //private ProgressThread progressThread; public LoginProgressDialog(Context ctx){ super(ctx); ... } } } ~~~ I also tried second approach, which moves the wait_thread into progress dialog class/object, following Google’s “Creating a ProgressDialog” (http://developer.android.com/guide/topics/ui/ dialogs.html#ProgressDialog). The 2nd login dialog is started by the progress dialog. Its wait() method gets called ONLY once (that is before 3nd showDialog(DIALOG_LOGIN) gets called). Seems to me the unfinished progressDialog’s thread blocks new progressDialog to be generated, I mean, when new showDialog(DIALOG_LOGIN_PROGRESS) called, the system will continue to use last progressDialog which has already responded to the first notify call and won’t respond to the notify call any more. So although the http thread handles well and call notify in due time, no one is waiting for that notify. Thus the system just hungs, while progress dialog is doing it animation endlessly. The followings are part of the code: … public class Test {// extends Activity implements Constants { ... @Override public void onCreate(Bundle savedInstanceState) { ... showDialog(DIALOG_LOGIN); // } ... @Override protected Dialog
[android-developers] Configure app to work horizontal and vertical?
Hi, Is it possible to configure all layouts of an Android app to support BOTH landscape and portrait mode so that the app will work both when phone is held vertically and horizontally. From my brief reading, it seems not. Am I right? -- 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] Re: Problem to show unicode strings in TextView
The Html.from(utfStringInDecimalForm).toString() works! Thank you so much Ludovic Perrier!! I have sent an email to Struts' mailing list, hoping they could correct this in the first place. QM --~--~-~--~~~---~--~~ 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] Re: Problem to show unicode strings in TextView
My server side is using Struts (2.1.7). Strangely, the jsp, using struts tags, usually outputs ideally encoded message which can be displayed by Android’s TextView. Only when it comes to using struts’ “iterator” tag, then decimal unicode are sent to the client, which is fine for browser, but causing problem for Android’s TextView. To transfer the decimal Unicode into hexadecimal one is rather straight forward on the phone side, but this incurs the performance drop. A painful decision to take may be to change the server technology from Struts to Spring, hoping Spring is better than Struts, while Spring may bring other benefit. --~--~-~--~~~---~--~~ 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] Re: Problem to show unicode strings in TextView
I have also tried to escape or #, e.g. replacing with #038; or amp; etc, but none of them work. On Oct 16, 5:18 pm, qmwestview qmwestv...@googlemail.com wrote: Hi there, My data (stored as UTF-8 in the SQL db), when arrive at the phone as json strings, appear to be decimalUnicode, such as #32422;#20811;#23567; When I use setText(...) to show them inTextView, they are shown in their original form, rather than the characters they represent. If I use their equivalent form of UTF-8, i.e. \u7ea6\u514b\u5C0f, they then are shown correctly as 约克小。 My questions are: 1. How to receive the data in UTF-8 rather than decimalunicode? (I tried InputStreamReader(inputStream, UTF-8) but seems not working) or 2. How to send the data in UTF-8 for Android rather than decimalunicode(the same decimalunicodework fine for browser)? or 3. Is there any function which can turn decimalunicodestring into UTF-8 string? 4. Any other advice please? Many thanks in advance, qmwestview --~--~-~--~~~---~--~~ 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] Problem to show unicode strings in TextView
Hi there, My data (stored as UTF-8 in the SQL db), when arrive at the phone as json strings, appear to be decimal Unicode, such as #32422;#20811;#23567; When I use setText(...) to show them in TextView, they are shown in their original form, rather than the characters they represent. If I use their equivalent form of UTF-8, i.e. \u7ea6\u514b\u5C0f, they then are shown correctly as 约克小。 My questions are: 1. How to receive the data in UTF-8 rather than decimal unicode? (I tried InputStreamReader(inputStream, UTF-8) but seems not working) or 2. How to send the data in UTF-8 for Android rather than decimal unicode (the same decimal unicode work fine for browser)? or 3. Is there any function which can turn decimal unicode string into UTF-8 string? 4. Any other advice please? Many thanks in advance, qmwestview --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---