我正在开发一个包含大量ListView的Android应用程序。我创建了自己的ListAdapter,但我对OnItemClickListener并不满意。如果每个项目都有其他功能,那么在项目上添加监听器的最佳方法是什么?
答案 0 :(得分:0)
你可以尝试这个,我使用这个自定义适配器& OnClickListener()
public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Jobs> jobsItems;
public CustomListAdapter(Activity activity, List<Jobs> jobsItems) {
this.activity = activity;
this.jobsItems = jobsItems;
}
@Override
public int getCount() {
return jobsItems.size();
}
@Override
public Object getItem(int location) {
return jobsItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.custom_list_row_no_preview, null);
Button submit = (Button) convertView.findViewById(R.id.btnSubmit);
serial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return convertView;
}
}
类似地,您可以将任何TextView,EditText或Button添加到ListView中并设置onCickListener()