我遇到了一个愚蠢的问题。 我已经完成了相同的工作,但是第二次尝试时,onItemClick没有做任何事情。我现在重新重新复训了很多次,但似乎没有什么能吸引我的注意力。请看一下,让我知道出了什么问题 所以这是我的设置。
活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_promotionale);
ListView mylist = (ListView) findViewById(R.id.lv_promotionale);
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Toast.makeText(PromotionaleActivity.this,"I touched an item at position"+Integer.toString(position),Toast.LENGTH_SHORT).show();
}
});
活动布局为:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="370dp"
android:id="@+id/lv_promotionale" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Some text here"
android:id="@+id/textView"
android:paddingLeft="15dp"
android:paddingStart="15dp"
android:paddingTop="15dp"
android:paddingRight="0dp"
android:paddingEnd="0dp"
android:paddingBottom="0dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
修改 这是我使用外部适配器加载listview数据的方法
public void LoadListWithStuff(){
SQLiteDatabase db = new myDbHelper(getApplicationContext()).getWritableDatabase();
Cursor mCursor = db.rawQuery("select _id,data,numar,idclient,numeclient,tipclient,trimisa from cereri_mst order by data,numar desc" , null);
idid.clear();
idclient.clear();
numeclient.clear();
tipclient.clear();
datacerere.clear();
numarcerere.clear();
trimisa.clear();
if (mCursor.moveToFirst()) {
do {
idid.add(Integer.toString(mCursor.getInt(0)));
datacerere.add(mCursor.getString(1));
numarcerere.add(mCursor.getString(2));
idclient.add(Integer.toString(mCursor.getInt(3)));
numeclient.add(mCursor.getString(4));
tipclient.add(mCursor.getString(5));
trimisa.add(mCursor.getString(6));
} while (mCursor.moveToNext());
}
DisplayCereriAdapter disadpt = new DisplayCereriAdapter(PromotionaleActivity.this,idid,idclient,
numeclient, tipclient,datacerere,numarcerere,trimisa);
ListView lv = (ListView) findViewById(R.id.lv_promotionale);
lv.setAdapter(disadpt);
mCursor.close();
db.close();
}
此外,我必须在此处说明列表视图已填充。我可以看到listView的内容。唯一的问题是我似乎无法捕获listview上的ItemClick和longClick事件......
为什么它不起作用????? 我在这里疯了...... 谢谢
答案 0 :(得分:0)
我找到的解决方案是停止使用checkBox并将其替换为ImageView ...现在一切正常