1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

OnClickListener


Last Updated:

  1. awmayhall

    awmayhall New Member This Topic's Starter

    Joined:
    Oct 24, 2010
    Messages:
    4
    Likes Received:
    0
    hey guys im new a little new to the forum and ive built several android applications before however this one seems to be a pain in the but, Im building my own Dialog box and working on handling a touch event, ive tried lots of things but for some reason i keep getting this error
    Code (Text):
    1. 10-27 21:52:37.965: WARN/dalvikvm(635): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    2. 10-27 21:52:37.985: ERROR/AndroidRuntime(635): FATAL EXCEPTION: main
    3. 10-27 21:52:37.985: ERROR/AndroidRuntime(635): java.lang.ClassCastException: android.widget.LinearLayout
    4. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at com.appsand.proto.ListViewDialog$ListItemsAdapter$1.onItemClick(ListViewDialog.java:70)
    5. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
    6. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at android.widget.ListView.performItemClick(ListView.java:3382)
    7. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
    8. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at android.os.Handler.handleCallback(Handler.java:587)
    9. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at android.os.Handler.dispatchMessage(Handler.java:92)
    10. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at android.os.Looper.loop(Looper.java:123)
    11. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    12. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at java.lang.reflect.Method.invokeNative(Native Method)
    13. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at java.lang.reflect.Method.invoke(Method.java:521)
    14. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    15. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    16. 10-27 21:52:37.985: ERROR/AndroidRuntime(635):     at dalvik.system.NativeStart.main(Native Method)
    17. 10-27 21:52:37.995: WARN/ActivityManager(61):   Force finishing activity com.appsand.proto/.ListViewDialog
    18. 10-27 21:52:38.515: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{43f8e9e0 com.appsand.proto/.ListViewDialog}
    19. 10-27 21:52:48.015: WARN/ActivityManager(61): Launch timeout has expired, giving up wake lock!
    20. 10-27 21:52:48.547: WARN/ActivityManager(61): Activity idle timeout for HistoryRecord{43f89460 com.appsand.proto/.AppSandUserSettingsActivity}
    21. 10-27 21:52:58.551: WARN/ActivityManager(61): Activity destroy timeout for HistoryRecord{43f8e9e0 com.appsand.proto/.ListViewDialog}
    22.  
    Im just wanting an on touch listener so i can start a new activity or even a sum activity it will be to open a gallery where users will be able to select default avatars or pick from their images or take a picture.

    here's the code maybe someone could hep me

    Code (Text):
    1.  
    2. package com.appsand.proto;
    3.  
    4. import java.util.ArrayList;
    5. import java.util.List;
    6. import android.app.Activity;
    7. import android.content.Context;
    8. import android.os.Bundle;
    9. import android.view.LayoutInflater;
    10. import android.view.View;
    11. import android.view.ViewGroup;
    12. import android.view.Window;
    13. import android.widget.ArrayAdapter;
    14. import android.widget.ImageView;
    15. import android.widget.ListView;
    16. import android.widget.TextView;
    17.  
    18. public class ListViewDialog extends Activity
    19. {
    20.     private List<String> listItems = new ArrayList<String>();
    21.     private ListItemsAdapter adapter = null;
    22.     private TextView text;
    23.     private ImageView icon;
    24.     private ListView list;
    25.    
    26.     /** Called when the activity is first created. */
    27.     @Override
    28.     public void onCreate(Bundle savedInstanceState)
    29.     {
    30.         super.onCreate(savedInstanceState);
    31.         LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    32.         final View layout = inflater.inflate(R.layout.dialog, (ViewGroup) findViewById(R.id.root));
    33.         setContentView(layout);
    34.         listItems.add(getResources().getString(R.string.default_avatar));
    35.         listItems.add(getResources().getString(R.string.user_avatar));
    36.         list = (ListView) findViewById(R.id.list);
    37.         adapter = new ListItemsAdapter(listItems);
    38.         list.setAdapter(adapter);        
    39.     }
    40.    
    41.     private class ListItemsAdapter extends ArrayAdapter<String>
    42.     {
    43.         public ListItemsAdapter(List<String> items)
    44.         {
    45.             super(ListViewDialog.this, android.R.layout.simple_list_item_1, items);
    46.         }
    47.  
    48.         public View getView(int position, View convertView, ViewGroup parent)
    49.         {
    50.             LayoutInflater inflater = getLayoutInflater();
    51.             convertView = inflater.inflate(R.layout.dialog_items, null);            
    52.             text = (TextView) convertView.findViewById(R.id.DialogText);
    53.             text.setText(listItems.get(position));
    54.             convertView.setTag(text);
    55.             icon=(ImageView)convertView.findViewById(R.id.DialogImage);
    56.             if (listItems.get(position).equals(getResources().getString(R.string.default_avatar)))
    57.                 icon.setImageResource(R.drawable.default01);
    58.             else
    59.                 icon.setImageResource(R.drawable.default04);            
    60.             return convertView;            
    61.         }
    62.     }
    63. }
     

    Advertisement

Share This Page

Loading...