各行に 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();
}
});