我有一个操作 10 行的 ListView。每行有两个TextView。如果我选择一行,我想知道当前的 TextView 文本。我知道 getView() 方法多次调用。出于这个原因,我没有得到确切的文字。假设如果我选择第一行,那么我会得到最后一行文本。如何摆脱这个问题。任何建议将不胜感激。这里的 getView() 方法:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listview_layout, null);
holder = new ViewHolder();
/*
* holder.rlListViewImg = (RelativeLayout) convertView
* .findViewById(R.id.rl_listview_img);
*/
holder.ivMain = (ImageView) convertView
.findViewById(R.id.image_view_main);
holder.tvModule = (TextView) convertView
.findViewById(R.id.tv_module);
holder.tvClasses = (TextView) convertView
.findViewById(R.id.tv_classes);
holder.tvHours = (TextView) convertView.findViewById(R.id.tv_hours);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.tvModule.setText(rowItem.getModule());
// mCurrentModule = rowItem.getModule();
holder.tvClasses.setText(rowItem.getClasses());
holder.tvHours.setText(rowItem.getHours());
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("MY TEXT", "" + rowItem.getModule());
Intent intent = new Intent(getContext(), ModuleActivity.class);
intent.putExtra("MODULE", rowItem.getModule());
getContext().startActivity(intent);
}
});
return convertView;
}