Question

Hi below is some code ive been playing with but when i debug it never gets to the onitemclicklisten routine can anyone help?

package sanderson.swords.mobilesales;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import android.widget.AdapterView.OnItemClickListener;

public class OrderProductSearch extends Activity {
 ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
    HashMap<String,String> item = new HashMap<String,String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    try{
        setContentView(R.layout.orderproducts);
    }
    catch (Exception e) {
        //
        String shaw="";
        shaw = e.getMessage();
    }

    //Create view of the list where content will be stored
    final ListView listContent = (ListView)findViewById(R.id.orderproductlistview); 

    //Set for fast scrolling 
    listContent.setFastScrollEnabled(true);

    //Create instance of the database
    final DbAdapter db = new DbAdapter(this); 

    //Open the Database and read from it
    db.openToRead();

    //Routine to call all product sub groups from the database
    final Cursor cursor = db.getAllSubGroupProduct();
   //Manages the cursor
    startManagingCursor(cursor);
    int i=0;
    cursor.moveToFirst();
    while (cursor.getPosition() < cursor.getCount()) {
         item.put("ProdName",cursor.getString(2));
         item.put("ProdSize", cursor.getString(3));
         item.put("ProdPack",cursor.getString(4));
         item.put("OrdQty","0");

         //list.add(item);
         list.add(i, item);
         item = new HashMap<String,String>();   
         cursor.moveToNext();
        i = i + 1;

    }

    String[] from = new String[] {"ProdName", "ProdSize", "ProdPack", "OrdQty"};

    int[] to = new int[] { R.id.productlinerow, R.id.productlinerow2, R.id.productlinerow3, R.id.productlinerow4};
    SimpleAdapter notes = new SimpleAdapter(OrderProductSearch.this,list,R.layout.productlinerow,from,to);                  
    listContent.setAdapter(notes);


    //Close the database
    db.close();     



    listContent.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {    

            String neil = "test";

            neil = neil + "test";

        }
      }); 


    }




 }
Was it helpful?

Solution

An easier way to verify the click listener is to add some logcat prints in it, e.g.

listContent.setOnItemClickListener(new OnItemClickListener() {
   public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {    

        Log.d(TAG, "Click!");
    }
  });

OTHER TIPS

If you set a breakpoint at

listContent.setOnItemClickListener(new OnItemClickListener() {

it may not break when you click.

Try setting a breakpoint at

String neil = "test";

and debugging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top