Question

I create a statistics activity with listView . but onItemClick Not working I surffed internet but given solution not working for me.

try
{
    int counter=0;
    db = helper.getReadableDatabase();
    c = db.query(DBHelper.Result, null, null, null, null, null, null);
    c.moveToFirst();
    do
    {
        counter++;
        States state = new States(c.getString(2), c.getString(3), false);
        stateList.add(state);
    }while(c.moveToNext());

    Log.d("counter", ""+counter);
    /*adapter = new SimpleCursorAdapter(this, R.layout.row, c, new String [] {DBHelper.R_test,DBHelper.R_testNM}, new int []{R.id.rowTxt1,R.id.rowTxt2});
    Lv.setAdapter(adapter);
    Lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);*/
    db.close();
}
catch(Exception e)
{
    e.printStackTrace();
    Log.d("Error", ""+e.getMessage());
}

// create an ArrayAdaptar from the String Array
dataAdapter = new MyCustomAdapter(this, R.layout.row, stateList);

//ListView listView = (ListView) findViewById(R.id.LvStatistics);
// Assign adapter to ListView
Lv.setAdapter(dataAdapter);

Lv.setOnItemClickListener(new OnItemClickListener() 
{
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) 
    {
        Log.d("click", "0");    
    }
});

row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Background"
android:orientation="vertical" >

<TextView
    android:id="@+id/rowTxt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="10dp"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/ExamFontColor"
    />

<TextView
    android:id="@+id/rowTxt2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/rowTxt1"
    android:layout_marginLeft="20dp"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/FontBlack"
   />

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="10dp"
    android:text="1" />

</RelativeLayout>

exam_statistics.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Background"
android:orientation="vertical" >

<TextView
    android:id="@+id/statisticsHeader"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@color/HeaderColor"
    android:gravity="center"
    android:text="@string/ButtonStatistics"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="@color/FontWhite"
    android:textSize="30sp" />

<ListView
    android:id="@+id/LvStatistics"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/btnDelete"
    android:background="@color/Background"
     >

</ListView>

<Button
    android:id="@+id/btnDelete"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/statisticsHeader"
    android:layout_marginBottom="10dp"
    android:background="@drawable/button_green_effect"
    android:text="@string/ButtonDelete"
    android:textColor="@color/FontWhite"
    android:textSize="27sp" />

</RelativeLayout>

I tried a Lot but not Working help me to solve this problem

Was it helpful?

Solution

write this in ur xml inside checkbox tag

android:focusable="false"

try after using this..

OTHER TIPS

If your MyCustomAdapter implements OnItemClickListener so you have to use the following code : MyCustomAdapter.setOnItemclikListener(dataAdapter);

As there is a checkBox in the row, ListView OnitemClickListener wont work. You can write OnItemClickLister in the row (Adapter) , to get the click event.

If you add args2 in log does it return the click position?

Log.d("click", "Row " + args.toString);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top