我有一个带有 textView 的列表视图,每行都有一个按钮,我试图通过单击按钮而不是单击整行而是单击 adapterView 方法来获取文本:(AdapterView arg0,View v,int position,long arg3)不适用于按钮单击。
public View getView(int position, View convertView, ViewGroup parent) {
//Set the view for each item in the list view
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.employeeitem, null);
}
//Get the Textviews from the row view and set the appropriate values for them
TextView labelName=(TextView) v.findViewById(R.id.labelName);
TextView labelAddress=(TextView)v.findViewById(R.id.labelAddress);
TextView labelImmat=(TextView)v.findViewById(R.id.labelImmat);
labelName.setText(array[position].marque);
labelAddress.setText(array[position].categorie);
labelImmat.setText(array[position].Prix_Achats);
return v;
}
这就是我通过单击列表视图的行来选择项目的方式,但是我想通过单击按钮而不是整行来选择项目:
listEmployeeDetails.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View v,int position, long arg3)
{
TextView tv=(TextView)v.findViewById(R.id.labelName);
String name=tv.getText().toString();
Toast.makeText(getApplicationContext(), "Contact Selected "+name, Toast.LENGTH_LONG).show();
}
});