我的自定义 ListView 适配器类是这样的。一旦按下项目(onclick),我想获取项目的索引号。如何获取索引号并将其传递给 int.. 我将获取索引号的代码位于 onCreate 方法之后。请帮我!
// On holder.txtstormName_Nice button click i want to get selected item index.
public class ListViewCustomAlerts extends BaseAdapter {
ArrayList<HurricaneBeanClass> itemList;
public Activity context;
public LayoutInflater inflater;
public ListViewCustomAlerts(Activity context,ArrayList<HurricaneBeanClass> arraylist_List)
{
super();
this.context = context;
this.itemList = arraylist_List;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return itemList.size();
}
@Override
public Object getItem(int position)
{
return itemList.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
p =position;
final ViewHolder holder;
if(convertView==null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.hurricane_row, null);
holder.txtstormName_Nice=(TextView)convertView.findViewById(R.id.hurricaneNameRowTextView);
convertView.setTag(holder);
}
else
holder=(ViewHolder)convertView.getTag();
HurricaneBeanClass bean = (HurricaneBeanClass) itemList.get(position);
holder.txtstormName_Nice.setText(bean.getStormName_Nice());
holder.txtstormName_Nice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//here i want item index.................
HurricaneBeanClass bean = (HurricaneBeanClass) itemList.get(position);
HurricaneActivity.curlat=bean.getCurentlat();
HurricaneActivity.curlon=bean.getCurentlon();
...
}
});
return convertView;
}
}
public static class ViewHolder
{
TextView txtstormName_Nice;
}