我改变了我最初的活动,SherlockActivity
以便从 ABS 的所有优势中受益。为此,我使用ListAdapterAnSco extends BaseAdapter
. 现在我想onclick
管理我onLongClick
的. 我使用了几种组合,但我做不到。getView
ListAdapter
注意:我使用SQLiteCursor
来获取物品
原始 OnItemClickListener 代码
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
Intent intent = new Intent(getApplicationContext(),ListPeriode.class);
SQLiteCursor cr=(SQLiteCursor)parent.getItemAtPosition(position);
String ansco=cr.getString(cr.getColumnIndex(DatabaseHelper.ANSCO));
AnSco an=new AnSco(ansco);
an.setIdan((int)id);
Toast.makeText(getApplicationContext(), "Année Scolaire: "+an.getAnsco(), Toast.LENGTH_LONG).show();
intent.putExtra("ANSCO_ID", an.getIdan());
intent.putExtra("ANSCO_AN", an.getAnsco());
cr.close();
startActivity(intent);
finish();
}
如何在 OnClick 方法中更改此代码以完成相同的工作?
我的getView
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.annee_sco_item, null);
// Locate the TextViews in listview_item.xml
holder.an = (TextView) view.findViewById(R.id.ansco_item);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.an.setText(listAnsco.get(position).getAnsco());
// Listen for ListView Item Click
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
return view;
}