OnItemClick & OnItemLongClick not work when just Button put in listview
when i am taking just button in listview
at that time i am shock to see OnItemClick & OnItemLongClick not work .
Please help...
dbshow.java
public class dbshow extends Activity implements OnItemClickListener,
OnItemLongClickListener {
private ListView lv_database;
private DAtahelper mhelper;
private SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
init();
showdataquery();
}
private void init() {
// TODO Auto-generated method stub
lv_database = (ListView) findViewById(R.id.lv_database);
lv_database.setOnItemClickListener(this);
lv_database.setOnItemLongClickListener(this);
}
@SuppressLint("NewApi")
private void showdataquery() {
// TODO Auto-generated method stub
mhelper = new DAtahelper(this);
db = mhelper.getReadableDatabase();
String columns[] = { "_id,name,city,phone" };
Cursor c = db.query("vishal", columns, null, null, null, null, null);
c.moveToFirst();
String[] from = { "name", "city", "phone" };
int[] to = { R.id.tv_name, R.id.tv_city, R.id.tv_phone };
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getApplicationContext(), R.layout.showdata, c, from, to, 0) {
};
lv_database.setAdapter(adapter);
}
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.e("", "long");
return false;
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Log.e("", "item");
}
}
listview.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lv_database"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
showdata.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="@android:color/black" />
<TextView
android:id="@+id/tv_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="@android:color/black" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/tv_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="@android:color/black" />
</LinearLayout>