我通过正确实施 onItemClick() 方法遇到了问题。但我不知道如何用英语表达我的问题以在谷歌上找到一些东西^^
问题:
我有一个列表视图。这个列表视图充满了类似的东西。任何任务都会激活另一个动作。我可以使用 value position
,但任务通常很复杂,因此position
不是正确的标识符。我需要标签之类的东西吗?
list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
}
});
适配器:
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import de.sebspr.app08.R;
public class HalleAdapter extends BaseAdapter {
private LayoutInflater layoutInflater;
private ArrayList<ItemHalle> listItem;
public HalleAdapter(Context context, ArrayList<ItemHalle> listItem){
this.listItem = listItem;
layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return listItem.size();
}
@Override
public Object getItem(int position) {
return listItem.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
convertView = layoutInflater.inflate(R.layout.halle_item, null);
holder = new ViewHolder();
holder.center = (TextView) convertView.findViewById(R.id.halletxt1);
holder.right = (TextView) convertView.findViewById(R.id.halletxt2);
holder.image = (ImageView) convertView.findViewById(R.id.halleimage);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.center.setText(listItem.get(position).getCenter());
holder.right.setText(listItem.get(position).getRight()
+de.sebspr.app08.MainActivity.getMContext()
.getResources().getString(R.string.geldZeichen));
holder.image.setImageDrawable(listItem.get(position).getIcon());
return convertView;
}
static class ViewHolder{
TextView center;
TextView right;
ImageView image;
}
}