मेरे पास एक सूची दृश्य के साथ एक एंड्रॉइड एप्लिकेशन है, ListView ठीक सेटअप करेगा लेकिन अब मैं ListView में एक छवि क्लिक करने योग्य होना चाहता हूं। मैं सूची को भरने के लिए 2 कक्षाओं, गतिविधि वर्ग (अभिभावक) और एक ArrayAdapter का उपयोग करके ऐसा करता हूं। ArrayAdapter में मैं उस सूची में छवि के लिए ऑनक्लिक लिस्टनर लागू करता हूं जिसे मैं क्लिक करने योग्य बनाना चाहता हूं।ListView के एडाप्टर कॉल पर ऑनक्लिक कैसे करें गतिविधि का कार्य
अभी तक यह सब काम करता है।
लेकिन अब जब मैं सूची में छवि के लिए ऑनक्लिक पर चलता हूं, तो गतिविधि गतिविधि से कोई फ़ंक्शन चलाने के लिए, लेकिन मुझे नहीं पता कि कैसे। नीचे 2 वर्ग हैं जिनका मैं उपयोग करता हूं।
पहले गतिविधि वर्ग:
public class parent_class extends Activity implements OnClickListener, OnItemClickListener
{
child_class_list myList;
ListView myListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// setup the Homelist data
myList = new child_class_list (this, Group_Names, Group_Dates);
myListView = (ListView) findViewById(R.id.list);
// set the HomeList
myListView.setAdapter(myList);
myListView.setOnItemClickListener(this);
}
void function_to_run()
{
// I want to run this function from the LiscView Onclick
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
// do something
}
}
और से जहाँ मैं गतिविधि वर्ग से एक समारोह कॉल करना चाहते हैं ArrayAdapter:
public class child_class_list extends ArrayAdapter<String>
{
// private
private final Context context;
private String[] mName;
private String[] mDate;
public child_class_list (Context context, String[] Name, String[] Date)
{
super(context, R.layout.l_home, GroupName);
this.context = context;
this.mName = Name;
this.mDate = Date;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.l_home, parent, false);
ImageView selectable_image = (ImageView) rowView.findViewById(R.id.l_selectable_image);
selectable_image.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// I want to run the function_to_run() function from the parant class here
}
}
);
// get the textID's
TextView tvName = (TextView) rowView.findViewById(R.id.l_name);
TextView tvDate = (TextView) rowView.findViewById(R.id.l_date);
// set the text
tvName.setText (mName[position]);
tvDate.setText (mDate[position]);
return rowView;
}
}
किसी को भी जानता है कि कैसे गतिविधि में समारोह को चलाने के लिए एरेडैडाप्टर से कक्षा या गतिविधि क्लास में छवि पर क्लिक करने के लिए क्लिक करें I मदद की बहुत सराहना करेंगे।
ग्रेट। सरल और प्रभावी। –