में क्लिक किए गए बटन से सूचीदृश्य आइटम प्राप्त करें मेरे पास दो बटन के साथ एक कस्टम सूची दृश्य है और जब मैं किसी भी पंक्ति पर बटन क्लिक करता हूं तो मैं सूचीदृश्य पर टेक्स्ट लेबल प्राप्त करना चाहता हूं और अभी बस एक टोस्ट पॉपअप करना चाहता हूं इसके साथ। अब तक कुछ भी काम नहीं किया है, मैं अपने सरणी में आखिरी वस्तु प्राप्त करता रहता हूं।एंड्रॉइड: कस्टम सूचीदृश्य
यहाँ एक स्क्रीन शॉट आप मैं क्या मतलब
यहाँ का एक बेहतर विचार देने के लिए अपने कस्टम 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();
'valueView.getText()।' Value] के स्थान पर 'textView.getText()। ToString() 'आज़माएं। –