Problem with onlistitemclick() when using multiple listviews

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Problem with onlistitemclick() when using multiple listviews

Postby zumpar » Fri Oct 30, 2009 5:21 pm

Hi,

there seem to be a lot of ListView questions on the forum but i didn't really find a similar one to mine. It might be a noobish question but please bear with me :) any help is appreciated!

Ive got a ListActivity with 3 lists in the layout of the app. When i wanted to populate the first ListView, ive had problems doing it, as i constantly got the error "your content must have a listview whose id attribute is 'list' ", so i did what everyone advised to do, and changed the id to: android:id="@android:id/list", and along with this code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ArrayAdapter<String> dAdapter = new ArrayAdapter<String>(this,R.layout.row, this.myList);
  3.  
  4.  
  5.  
  6. this.setListAdapter(dAdapter);
  7.  
  8.  
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


it worked.. even though i have tried many times to not do it this way, but never succeeded.
The two other ListViews are populated in the normal fashion:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ListView myView = (ListView)findviewbyid......
  3.  
  4. myView.setAdapter(...)
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


The thing is, i can't get the onListItemClick(ListView l, ...) to work on the other two lists. I tried using an if-statement inside the onlistitemclick listener, which looked something like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. if (l == (ListView)findViewById(R.id.secondView)) { then do something else}  or
  3.  
  4. if (l.equals((ListView)findViewById(R.id.thirdView))){ do something else}
  5.  
  6.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


but i had no luck with that. Those conditions were never true, and the program never entered the if statement.. so my question is am i doing something wrong ?(im assuming so) What is the correct way to check which ListView was clicked?

Thanks!
zumpar
Freshman
Freshman
 
Posts: 7
Joined: Thu Oct 08, 2009 2:07 pm

Top

Postby wiederke » Fri Oct 30, 2009 8:24 pm

Hi,

the ListActivity is only useful if you use exactly one ListView in your activity. Then you don't need to implement some boilerplate code to access the list view.

With your 3 ListView you should extend an normal activity and add the ListViews like you did with your second and third ListView. Use the method ListView.setOnItemClickListener on each of your list views to add a OnItemClickListener to each ListView separatly.


Bye

Torsten
wiederke
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Mon Mar 02, 2009 6:46 pm
Location: Germany

Thanks!

Postby zumpar » Fri Oct 30, 2009 11:48 pm

Ah, thanks for the quick reply and for shedding some light on this topic, it really helped me out.

I changed it from a ListActivity to just an Activity,

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. @Override
  3.  
  4. protected void onListItemClick(ListView l, View v, int position, long id) {
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


to

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public OnItemClickListener theListListener = new OnItemClickListener() {
  3.  
  4. public void onItemClick(android.widget.AdapterView<?> parent, View v, int position, long id) { .. } };
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


and voila, works :)

Thanks!
zumpar
Freshman
Freshman
 
Posts: 7
Joined: Thu Oct 08, 2009 2:07 pm

Postby Zeba Momin » Thu Dec 17, 2009 11:55 am

hi,
I'm using the ListView as :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class baseForm extends ListActivity {
  2.  
  3.         public ListView lvList;
  4.  
  5.         // for list view
  6.  
  7.         private ArrayList<ListItem> m_orders = null;
  8.  
  9.         private OrderAdapter m_adapter;
  10.  
  11.         private Runnable viewOrders;
  12.  
  13.         private OnItemClickListener listClickListener;
  14.  
  15.  
  16.  
  17.         public void onCreate(Bundle icicle) {
  18.  
  19.                 super.onCreate(icicle);
  20.  
  21.                 setContentView(R.layout.base_form);
  22.  
  23.                 lvList = getListView();
  24.  
  25.                 lvList.setOnItemClickListener(listClickListener);
  26.  
  27.                 listClickListener = new OnItemClickListener() {
  28.  
  29.                         public void onItemClick(AdapterView<?> parent, View v,
  30.  
  31.                                         int position, long id) {
  32.  
  33.                                 System.out.println("list item clicked at :"+position);
  34.  
  35.  
  36.  
  37.                         }
  38.  
  39.                 };
  40.  
  41.          }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


But the onItemClick() function doesn't get called on an list item click!! :(
The xml layout is
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ListView android:id="@android:id/list" android:layout_width="fill_parent"
  2.  
  3.                 android:layout_height="fill_parent" android:background="@drawable/back_grnd"
  4.  
  5.                 android:listSelector="@drawable/list_select_back" android:clickable="true"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Can sumone plzzzz help me wid dis... Thank You...
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Postby achie1266 » Thu Dec 17, 2009 12:48 pm

listClickListener has not been initialized at the time when you set it to the listView. ou are initializing it after you set it to the listview.
Try initializing your onListItemClick first and then set it to the list. or just remove the onItemClickListener and overwrite it as a seperate method if you are still not able to get it.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Zeba Momin » Thu Dec 17, 2009 1:43 pm

this is wat i tried now
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle icicle) {
  2.  
  3.                 super.onCreate(icicle);
  4.  
  5.                 setContentView(R.layout.base_form);
  6.  
  7.                 lvList = getListView();
  8.  
  9.                 listClickListener = new OnItemClickListener() {
  10.  
  11.                         public void onItemClick(AdapterView<?> parent, View v,
  12.  
  13.                                         int position, long id) {
  14.  
  15.                                 System.out.println("::::list clicked from listener::::"+position);
  16.  
  17.  
  18.  
  19.                         }
  20.  
  21.                 };
  22.  
  23.  
  24.  
  25.                 lvList.setOnItemClickListener(listClickListener);
  26.  
  27.     }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


but it still doesnt seem to wrk...!!!!

I also tried
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class baseForm extends ListActivity implements OnItemClickListener {
  3.  
  4.  public ListView lvList;
  5.  
  6.      // for list view
  7.  
  8.      private ArrayList<ListItem> m_orders = null;
  9.  
  10.      private OrderAdapter m_adapter;
  11.  
  12.      private Runnable viewOrders;
  13.  
  14.      private OnItemClickListener listClickListener;
  15.  
  16.  
  17.  
  18.      public void onCreate(Bundle icicle) {
  19.  
  20.           super.onCreate(icicle);
  21.  
  22.           setContentView(R.layout.base_form);
  23.  
  24. }
  25.  
  26.      @Override
  27.  
  28.         public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  29.  
  30.                  System.out.println("list item clicked ");
  31.  
  32.                
  33.  
  34.         }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


But even dis didnt wrk..!!
Wat am I going wrong???
Plzzz help...
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Top

Postby achie1266 » Thu Dec 17, 2009 2:15 pm

I could not find where you have set the listadapter[i am guessing you extended either the base adapter or array adapter]
can you post the layout file and your activity class which you are using so that I can test it out.

what do you mean by it doesn't work.. What error does it give? I would guess its going to some nullPointerException but I cant recreate your problem untill i have the layout and your java class.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Zeba Momin » Thu Dec 17, 2009 2:19 pm

thank you for replying again
My .java file is:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.util.ArrayList;
  2.  
  3.  
  4.  
  5. import android.app.ListActivity;
  6.  
  7. import android.app.ProgressDialog;
  8.  
  9. import android.content.Context;
  10.  
  11. import android.graphics.drawable.Drawable;
  12.  
  13. import android.os.Bundle;
  14.  
  15. import android.util.Log;
  16.  
  17. import android.view.LayoutInflater;
  18.  
  19. import android.view.View;
  20.  
  21. import android.view.ViewGroup;
  22.  
  23. import android.view.View.OnClickListener;
  24.  
  25. import android.widget.AdapterView;
  26.  
  27. import android.widget.ArrayAdapter;
  28.  
  29. import android.widget.ImageButton;
  30.  
  31. import android.widget.ListView;
  32.  
  33. import android.widget.TextView;
  34.  
  35. import android.widget.AdapterView.OnItemClickListener;
  36.  
  37.  
  38.  
  39. public class baseForm extends ListActivity implements OnItemClickListener{
  40.  
  41.         private ImageButton backBtn;
  42.  
  43.         private ImageButton logoBtn;
  44.  
  45.         private ImageButton shareBtn;
  46.  
  47.         private ImageButton iconL;
  48.  
  49.         private ImageButton iconR;
  50.  
  51.         private TextView tvTitle;
  52.  
  53.         private TextView tvHeading;
  54.  
  55.         private TextView tvInfoL;
  56.  
  57.         private TextView tvInfoR;
  58.  
  59.         public ListView lvList;
  60.  
  61.         private String sTitle = "";
  62.  
  63.         // for list view
  64.  
  65.         // private ProgressDialog m_ProgressDialog = null;
  66.  
  67.         private ArrayList<ListItem> m_orders = null;
  68.  
  69.         private OrderAdapter m_adapter;
  70.  
  71.         private Runnable viewOrders;
  72.  
  73.         private static EnumScreenType eScreenType;
  74.  
  75.         private static EnumItemType itemType;
  76.  
  77.         private OnItemClickListener listClickListener;
  78.  
  79.  
  80.  
  81.         public void onCreate(Bundle icicle) {
  82.  
  83.                 super.onCreate(icicle);
  84.  
  85.                 setContentView(R.layout.base_form);
  86.  
  87.                 lvList = getListView();
  88.  
  89.                 listClickListener = new OnItemClickListener() {
  90.  
  91.                         public void onItemClick(AdapterView<?> parent, View v,
  92.  
  93.                                         int position, long id) {
  94.  
  95.                                 System.out.println("::::list clicked from listener::::"+position);
  96.  
  97.  
  98.  
  99.                         }
  100.  
  101.                 };
  102.  
  103.  
  104.  
  105.                 lvList.setOnItemClickListener(listClickListener);
  106.  
  107.                 m_orders = new ArrayList<ListItem>();
  108.  
  109.                 this.m_adapter = new OrderAdapter(this, R.layout.listitem, m_orders);
  110.  
  111.                 setListAdapter(this.m_adapter);
  112.  
  113.  
  114.  
  115.                 viewOrders = new Runnable() {
  116.  
  117.                         @Override
  118.  
  119.                         public void run() {
  120.  
  121.                                 getOrders();
  122.  
  123.                         }
  124.  
  125.                 };
  126.  
  127.                 Thread thread = new Thread(null, viewOrders, "MagentoBackground");
  128.  
  129.                 thread.start();
  130.  
  131.  
  132.  
  133.                                
  134.  
  135.         }
  136.  
  137.  
  138.  
  139.  
  140.  
  141.         private Runnable returnRes = new Runnable() {
  142.  
  143.                 @Override
  144.  
  145.                 public void run() {
  146.  
  147.                         int size=m_orders.size();
  148.  
  149.                         if (m_orders != null && m_orders.size() > 0) {
  150.  
  151.                                 m_adapter.notifyDataSetChanged();
  152.  
  153.                                 for (int i = 0; i < size; i++)
  154.  
  155.                                         m_adapter.add(m_orders.get(i));
  156.  
  157.                         }
  158.  
  159.                         m_adapter.notifyDataSetChanged();
  160.  
  161.                 }
  162.  
  163.         };
  164.  
  165.  
  166.  
  167.         private void getOrders() {
  168.  
  169.                 try {
  170.  
  171.                         m_orders = new ArrayList<ListItem>();
  172.  
  173.                         ListScreenData oListScreenData = new ListScreenData();
  174.  
  175.                         oListScreenData.fillListItem(m_orders, eScreenType);
  176.  
  177.                         System.out.println("oListScreenData created..//....."
  178.  
  179.                                         + m_orders.size());
  180.  
  181.                 } catch (Exception e) {
  182.  
  183.                         Log.e("BACKGROUND_PROC", e.getMessage());
  184.  
  185.                 }
  186.  
  187.                 runOnUiThread(returnRes);
  188.  
  189.         }
  190.  
  191.  
  192.  
  193.         private class OrderAdapter extends ArrayAdapter<ListItem> {
  194.  
  195.  
  196.  
  197.                 private ArrayList<ListItem> items;
  198.  
  199.  
  200.  
  201.                 public OrderAdapter(Context context, int textViewResourceId,
  202.  
  203.                                 ArrayList<ListItem> items) {
  204.  
  205.                         super(context, textViewResourceId, items);
  206.  
  207.                         this.items = items;
  208.  
  209.                 }
  210.  
  211.  
  212.  
  213.                 @Override
  214.  
  215.                 public View getView(int position, View convertView, ViewGroup parent) {
  216.  
  217.  
  218.  
  219.                         View v = convertView;
  220.  
  221.                         if (v == null) {
  222.  
  223.                                 LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  224.  
  225.                                 v = vi.inflate(R.layout.listitem, null);
  226.  
  227.                         }
  228.  
  229.                         ListItem o = items.get(position);
  230.  
  231.                         if (o != null) {
  232.  
  233.                                 tvHeading = (TextView) v.findViewById(R.id.toptext);
  234.  
  235.                                 tvInfoL = (TextView) v.findViewById(R.id.bottomtextleft);
  236.  
  237.                                 tvInfoR = (TextView) v.findViewById(R.id.bottomtextright);
  238.  
  239.                                 iconL = (ImageButton) v.findViewById(R.id.iconL);
  240.  
  241.                                 iconR = (ImageButton) v.findViewById(R.id.iconR);
  242.  
  243.                                 System.out.println("in get view...got all stuff.....");
  244.  
  245.                                 if (tvHeading != null) {
  246.  
  247.                                         o.getHeading();
  248.  
  249.                                         tvHeading.setText(o.sHeading);
  250.  
  251.                                 }
  252.  
  253.                                 if (tvInfoL != null) {
  254.  
  255.                                         o.getSubheadingL();
  256.  
  257.                                         if (o.sSubHeadingL == null) {
  258.  
  259.                                                 tvInfoL.setVisibility(View.GONE);
  260.  
  261.                                         } else {
  262.  
  263.                                                 tvInfoL.setVisibility(View.VISIBLE);
  264.  
  265.                                                 tvInfoL.setText(o.sSubHeadingL);
  266.  
  267.                                         }
  268.  
  269.                                 }
  270.  
  271.                                 if (tvInfoR != null) {
  272.  
  273.                                         o.getSubheadingR();
  274.  
  275.                                         if (o.sSubHeadingR == null) {
  276.  
  277.                                                 tvInfoR.setVisibility(View.GONE);
  278.  
  279.                                         } else {
  280.  
  281.                                                 tvInfoR.setVisibility(View.VISIBLE);
  282.  
  283.                                                 tvInfoR.setText(o.sSubHeadingR);
  284.  
  285.                                         }
  286.  
  287.                                 }
  288.  
  289.  
  290.  
  291.                                 if (iconL != null) {
  292.  
  293.                                         o.getIconLeftImage();
  294.  
  295.                                         if (o.bIconL == true) {
  296.  
  297.                                                 if (o.bFolder == true) {
  298.  
  299.                                                         iconL
  300.  
  301.                                                                         .setBackgroundDrawable(Main.objGUIEngine
  302.  
  303.                                                                                         .getIconImage(
  304.  
  305.                                                                                                         EnumItemType.FolderBttnLeft_ItemType,
  306.  
  307.                                                                                                         false, null, null));
  308.  
  309.                                                 }
  310.  
  311.                                                 iconL.setVisibility(View.VISIBLE);
  312.  
  313.                                         } else {
  314.  
  315.                                                 iconL.setVisibility(View.GONE);
  316.  
  317.                                         }
  318.  
  319.                                 }
  320.  
  321.  
  322.  
  323.                                 if (iconR != null) {
  324.  
  325.                                         o.getIconRightImage();
  326.  
  327.                                         if (o.bIconR == true && o.bFolder == true) {
  328.  
  329.                                                 iconR.setBackgroundDrawable(Main.objGUIEngine
  330.  
  331.                                                                 .getIconImage(
  332.  
  333.                                                                                 EnumItemType.FolderBttnRight_ItemType,
  334.  
  335.                                                                                 null, null, null));
  336.  
  337.                                                 iconR.setVisibility(View.VISIBLE);
  338.  
  339.  
  340.  
  341.                                         } else {
  342.  
  343.                                                 iconR.setVisibility(View.GONE);
  344.  
  345.                                         }
  346.  
  347.  
  348.  
  349.                                 }
  350.  
  351.                         }
  352.  
  353.                         return v;
  354.  
  355.                 }
  356.  
  357.         }
  358.  
  359.  
  360.  
  361.         @Override
  362.  
  363.         public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  364.  
  365.                 System.out.println("::::list clicked from listener::::");
  366.  
  367.                
  368.  
  369.         }
  370.  
  371.  
  372.  
  373. }
Parsed in 0.058 seconds, using GeSHi 1.0.8.4


and layout file is:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.         android:orientation="vertical" android:layout_width="fill_parent"
  7.  
  8.         android:layout_height="fill_parent">
  9.  
  10.  
  11.  
  12.         <RelativeLayout android:id="@+id/Header"
  13.  
  14.                 android:layout_toRightOf="@+id/btnBack" android:layout_height="40dip"
  15.  
  16.                 android:background="@drawable/topbar320px2" android:layout_width="fill_parent">
  17.  
  18.                 <ImageButton android:id="@+id/Back" android:layout_height="wrap_content"
  19.  
  20.                         android:layout_width="wrap_content" android:layout_marginLeft="0dip"
  21.  
  22.                         android:visibility="invisible" android:background="@drawable/topbar_back_up_320x480"/>
  23.  
  24.                 <TextView android:layout_toRightOf="@+id/Back" android:id="@+id/Title"
  25.  
  26.                         android:layout_width="wrap_content" android:layout_height="wrap_content"
  27.  
  28.                         android:layout_marginTop="10dip" android:layout_marginLeft="20dip"
  29.  
  30.                         android:textStyle="bold" android:textColor="#ffffff"
  31.  
  32.                         android:soundEffectsEnabled="false" android:textSize="20dip"
  33.  
  34.                         android:layout_marginBottom="15dip" android:gravity="center_vertical"
  35.  
  36.                         android:layout_marginRight="10dip" />
  37.  
  38.                 <ImageButton android:layout_toRightOf="@+id/Title"
  39.  
  40.                         android:id="@+id/Logo" android:layout_height="wrap_content"
  41.  
  42.                         android:layout_width="wrap_content" android:background="@drawable/logo"
  43.  
  44.                         android:layout_marginLeft="25dip" />
  45.  
  46.                 <ImageButton android:layout_toRightOf="@+id/Logo"
  47.  
  48.                         android:id="@+id/Share" android:layout_height="wrap_content"
  49.  
  50.                         android:layout_width="wrap_content" android:background="@drawable/topbar_share_up_320x480"
  51.  
  52.                         android:layout_marginLeft="101dip" android:visibility="invisible" />
  53.  
  54.         </RelativeLayout>
  55.  
  56.        
  57.  
  58.         <ImageButton android:id="@+id/Dragger"
  59.  
  60.                 android:layout_height="wrap_content" android:layout_width="wrap_content"
  61.  
  62.                 android:background="@drawable/dragger_open_down" android:clickable="true" />
  63.  
  64.  
  65.  
  66.         <ListView android:id="@android:id/list" android:layout_width="fill_parent"
  67.  
  68.                 android:layout_height="fill_parent" android:background="@drawable/back_grnd"
  69.  
  70.                 android:listSelector="@drawable/list_select_back" android:clickable="true"/>
  71.  
  72.  
  73.  
  74. </LinearLayout>
Parsed in 0.008 seconds, using GeSHi 1.0.8.4


and it doesnt work means... I dont get the sop out on my logcat console when i click on a list item..I donot get ne error of ne sorts...
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Postby achie1266 » Thu Dec 17, 2009 3:03 pm

the problem is with the java class, I do not see any problems in the listlayout. I did not test it out or examine clearly, I just looked at the id]

can you try making these changres in your java class
remove the
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. lvList = getListView();
  2.  
  3.           listClickListener = new OnItemClickListener() {
  4.  
  5.                public void onItemClick(AdapterView<?> parent, View v,
  6.  
  7.                          int position, long id) {
  8.  
  9.                     System.out.println("::::list clicked from listener::::"+position);
  10.  
  11.  
  12.  
  13.                }
  14.  
  15.           };
  16.  
  17.  
  18.  
  19.           lvList.setOnItemClickListener(listClickListener);
Parsed in 0.037 seconds, using GeSHi 1.0.8.4

and try to implement that logic in your onItemClick method which you are implementing since you need to implement that method from the interface.

2nd option
try to modify your code to even remove that interface and just override the onListItemClick method. I normally use this but its just a matter of preference and what we need.
Here is how you code may look like one you follow the second option
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.achie.test;
  2.  
  3.  
  4.  
  5.  
  6.  
  7. import java.util.ArrayList;
  8.  
  9.  
  10.  
  11. import android.app.ListActivity;
  12.  
  13. import android.app.ProgressDialog;
  14.  
  15. import android.content.Context;
  16.  
  17. import android.graphics.drawable.Drawable;
  18.  
  19. import android.os.Bundle;
  20.  
  21. import android.util.Log;
  22.  
  23. import android.view.LayoutInflater;
  24.  
  25. import android.view.View;
  26.  
  27. import android.view.ViewGroup;
  28.  
  29. import android.view.View.OnClickListener;
  30.  
  31. import android.widget.AdapterView;
  32.  
  33. import android.widget.ArrayAdapter;
  34.  
  35. import android.widget.ImageButton;
  36.  
  37. import android.widget.ListView;
  38.  
  39. import android.widget.TextView;
  40.  
  41. import android.widget.AdapterView.OnItemClickListener;
  42.  
  43. //removed the interface implementation[rename the class to your class]
  44.  
  45. public class Sample1 extends ListActivity{
  46.  
  47.      private ImageButton backBtn;
  48.  
  49.      private ImageButton logoBtn;
  50.  
  51.      private ImageButton shareBtn;
  52.  
  53.      private ImageButton iconL;
  54.  
  55.      private ImageButton iconR;
  56.  
  57.      private TextView tvTitle;
  58.  
  59.      private TextView tvHeading;
  60.  
  61.      private TextView tvInfoL;
  62.  
  63.      private TextView tvInfoR;
  64.  
  65.      public ListView lvList;
  66.  
  67.      private String sTitle = "";
  68.  
  69.      // for list view
  70.  
  71.      // private ProgressDialog m_ProgressDialog = null;
  72.  
  73.      private ArrayList<ListItem> m_orders = null;
  74.  
  75.      private OrderAdapter m_adapter;
  76.  
  77.      private Runnable viewOrders;
  78.  
  79.      private static EnumScreenType eScreenType;
  80.  
  81.      private static EnumItemType itemType;
  82.  
  83. //     private OnItemClickListener listClickListener;
  84.  
  85.  
  86.  
  87.      public void onCreate(Bundle icicle) {
  88.  
  89.           super.onCreate(icicle);
  90.  
  91.           setContentView(R.layout.base_form);
  92.  
  93. //          lvList = getListView();
  94.  
  95. //          listClickListener = new OnItemClickListener() {
  96.  
  97. //               public void onItemClick(AdapterView<?> parent, View v,
  98.  
  99. //                         int position, long id) {
  100.  
  101. //                    System.out.println("::::list clicked from listener::::"+position);
  102.  
  103. //
  104.  
  105. //               }
  106.  
  107. //          };
  108.  
  109. //
  110.  
  111. //          lvList.setOnItemClickListener(listClickListener);
  112.  
  113.           m_orders = new ArrayList<ListItem>();
  114.  
  115.           this.m_adapter = new OrderAdapter(this, R.layout.listitem, m_orders);
  116.  
  117.           setListAdapter(this.m_adapter);
  118.  
  119.  
  120.  
  121.           viewOrders = new Runnable() {
  122.  
  123.                @Override
  124.  
  125.                public void run() {
  126.  
  127.                     getOrders();
  128.  
  129.                }
  130.  
  131.           };
  132.  
  133.           Thread thread = new Thread(null, viewOrders, "MagentoBackground");
  134.  
  135.           thread.start();
  136.  
  137.  
  138.  
  139.                    
  140.  
  141.      }
  142.  
  143.  
  144.  
  145.      //your methods
  146.  
  147.  
  148.  
  149.      private class OrderAdapter extends ArrayAdapter<ListItem> {
  150.  
  151.  
  152.  
  153.           private ArrayList<ListItem> items;
  154.  
  155.  
  156.  
  157.           public OrderAdapter(Context context, int textViewResourceId,
  158.  
  159.                     ArrayList<ListItem> items) {
  160.  
  161.                super(context, textViewResourceId, items);
  162.  
  163.                this.items = items;
  164.  
  165.           }
  166.  
  167.           // your implementation
  168.  
  169.      }
  170.  
  171.  
  172.  
  173.      //changed to the method you need to override
  174.  
  175.      protected void onListItemClick(ListView l, View v, int position, long id) {
  176.  
  177.           // TODO Auto-generated method stub
  178.  
  179.          
  180.  
  181.      }
  182.  
  183.  
  184.  
  185. }
  186.  
  187.  
Parsed in 0.048 seconds, using GeSHi 1.0.8.4
I posted comments in the code where you might need changes.
Hope it helps you
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Zeba Momin » Fri Dec 18, 2009 10:40 am

Hey...
I tried the solution u mentioned above..but yet i did not get the onClick event!!!!
I den tried with an sample application, which has the ListActivity as its launcher activity in the manifest file of the application and it worked.... the callback was called!!!
In my application... I hav another activity 'GUIEngine' as my launcher activity in which at some point of time..the ListActivity 'baseForm' in started as:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent mainIntent = new Intent(GUIEngine.this, baseForm.class);
  2.  
  3.                 GUIEngine.this.startActivity(mainIntent);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

So, is it dat..the GUIEngine is getting the onclick event??? :?:
Plzz help me out wid dis..I'm stuck on dis since d last 2 days.. :(
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Postby achie1266 » Fri Dec 18, 2009 11:31 am

what are the changes that you made? came u post that java file.

Did you remove the implements interface on your class and then try setting the onlistItemClick on the listView too?
somethinglike

public class baseForm extends ListActivity[try extending Activity too]

and in ur method

ListView lv = (ListView)findViewById(R.id.your_list);
lv.setOnListItemClick(new .......)

You may even extend just an Activity and customize every thing.
PM me your email if it doesn't work and I can send you a sample application that I did. ( I can't do it right away though as I am off to bed [i live in mountain time]).

There is a post that i posted which has a code with another problem but with a working onItemClickListener. you may check it out from my posts.

good luck.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby Zeba Momin » Sat Dec 19, 2009 12:02 pm

Hello achie...
I solved the problem atlast!!!!
The callback was not happening as I had a ImageButton in my row layout :!:

Thanks for all your help :)
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 6 guests