두 개의 단추가있는 사용자 지정 ListView가 있습니다. 각 행의 단추 하나를 클릭하면 목록보기에서 텍스트 레이블을 얻고 싶습니다. 그것으로. 지금까지 아무 것도 작동하지 않고 배열에서 마지막 항목을 계속 가져 왔습니다. 여기 Android : 사용자 지정 목록보기에서 클릭 한 목록보기 항목 가져 오기
내 사용자 지정 ListView에 대한 내 어댑터 서브 클래스 당신에게 내가 여기을 무엇을 의미하는지의 더 나은 아이디어를 줄 수있는 스크린 샷입니다
static final String[] Names =
new String[] { "John", "Mike", "Maria", "Miguel"};
class MyArrayAdapter extends ArrayAdapter<String> {
private final Context context;
int which;
public MyArrayAdapter(Context context, String[] pValues) {
super(context, R.layout.main, pValues);
this.context = context;
values = pValues;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.main, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
Button call = (Button) rowView.findViewById(R.id.button1);
Button chat = (Button) rowView.findViewById(R.id.button2);
textView.setText(values[position]);
// Change icon based on name
s = values[position];
which = position;
call.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String name = values[which];
Toast.makeText(CustomListView.this, name, Toast.LENGTH_SHORT).show();
}
});
return rowView;
}
}
편집 :
String name = textView.getText().toString();
RelativeLayout ll = (RelativeLayout)v.getParent();
textView = (TextView)ll.findViewById(R.id.label);
Toast.makeText(CustomListView.this, name,
Toast.LENGTH_SHORT).show();
'values [which] '대신'textView.getText(). toString()'을 사용하십시오. –