में अशक्त मैं एक कस्टम संवाद लिखने और अपनी मूल गतिविधि से कुछ डेटा प्राप्त करने की कोशिश देता है, लेकिन मैं हमेशा अशक्त मिलता है जब मैं getOwnerActivity कहते हैं, किसी को भी मुझे बता वजह से ऐसा हो सकता है? TestDialogActivity से डेटा दिखाने में विफल होने पर मैं डेमोडियलॉग में डेटा क्यों दिखा सकता हूं?getOwnerActivity कस्टम संवाद
अग्रिम में बहुत धन्यवाद।
DialogTestActivity
public class DialogTestActivity extends Activity {
List<String> data = new ArrayList<String>();
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
showDialog(0);
}
});
}
public List<String> getData(){
data.add("one");
data.add("two");
data.add("three");
return data;
}
public Dialog onCreateDialog(int id){
return new DemoDialog(this);
}
}
DemoDialog
public class DemoDialog extends Dialog {
Context context;
public DemoDialog(Context context) {
super(context);
setContentView(R.layout.dialog);
this.context = context;
setTitle("Delete City");
ListView list = (ListView)findViewById(R.id.list);
ArrayAdapter<String> aa = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_multiple_choice, ((DialogTestActivity)getOwnerActivity()).getData());
// ArrayAdapter<String> aa = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_multiple_choice, getData());
list.setAdapter(aa);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
private List<String> getData(){
List<String> data = new ArrayList<String>();
data.add("1");
data.add("2");
return data;
}
}
नोट: मेरा मतलब है संवाद की OnCreate() कॉल। हालांकि, अगर आप विफल हो जाते हैं, तो आपको इसे अटैचट टॉविंडो() में डालने की आवश्यकता हो सकती है, क्योंकि एंड्रॉइड वास्तव में अपने जादू को मनमाने ढंग से रोक सकता है। उस ने कहा, यदि आपको निर्माता से मालिक तक पहुंचने की आवश्यकता है, तो मालिक "संदर्भ" है, इसलिए बस "संदर्भ" का उपयोग करें :) – Sajid
आपके उत्तर के लिए धन्यवाद, साजिद। मैंने आपके सुझाव का पालन करने की कोशिश की लेकिन साइटल शून्य हो गया, क्या आप अपना कोड साझा कर सकते हैं? – eric2323223
ऊपर एक संपादन के रूप में जोड़ा गया। आपको एटैच टॉविंडो() पर जांच करनी होगी। – Sajid