2011-09-13 6 views
7

सवाल यह है कि आप देख सकते हैं कि मैं showDialog() से पहले गतिशीलता के मान को सेट नहीं कर सकता।एक टेक्स्ट बॉक्स में एक एडिटेक्स्ट में टेक्स्ट कैसे सेट करें?

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.os.Bundle; 
import android.telephony.TelephonyManager; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.TextView; 


public class MainActivity extends Activity { 
private static final int DIALOG_TEXT_ENTRY = 7; 

private int user_id; 
private int dialogChoice; 
private String mobileNum; 
private EditText input2 ; 
private EditText input1 ; 
public TextView textView; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.alert_dialog_text_entry); 
    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); 
    mobileNum =tm.getLine1Number(); 
    // input1.setText(mobileNum); 
    textView.setText("hello"); 
    showDialog(DIALOG_TEXT_ENTRY); 

} 
@Override 
protected Dialog onCreateDialog(int i) { 


    switch (i) { 

    case DIALOG_TEXT_ENTRY: 
      LayoutInflater factory = LayoutInflater.from(this); 
      final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null); 
      input2 = (EditText) textEntryView.findViewById(R.id.number_edit); 
      input1 = (EditText) textEntryView.findViewById(R.id.username_edit); 
      textView = (TextView) textEntryView.findViewById(R.id.username_view); 
      return new AlertDialog.Builder(MainActivity.this) 
       // .setIconAttribute(android.R.attr.accountType) 
       .setTitle(R.string.alert_dialog_text_entry) 
       .setView(textEntryView) 
       .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 
          Intent i = new Intent(MainActivity.this, IccActivity.class); 
          startActivity(i); 
         /* User clicked OK so do some stuff */ 
        } 
       }) 
       .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 

         /* User clicked cancel so do some stuff */ 
        } 
       }) 
       .create(); 
    } 
    return null; 
} 

} पहले से

textView.setText("hello"); this line kills the app. 

धन्यवाद।

उत्तर

1

आपको textView.setText("hello"); को onCreateDialog() विधि में डाल देना चाहिए क्योंकि आप इसे आरंभ करने से पहले मूल्य निर्धारित कर रहे हैं।

+0

धन्यवाद की कोशिश करो। यह काम करता हैं। मैं इसका संदर्भ पाने से पहले एक मूल्य आवंटित करने की कोशिश कर रहा था। – akd

+0

अब आपको जवाब स्वीकार करना चाहिए क्योंकि यह अनुत्तरित के रूप में बह जाएगा –

1

आपने टेक्स्ट व्यू प्रारंभ नहीं किया है। मुझे लगता है कि आप NullPointerException हो रही है आप अपने onCreate में इस की जरूरत है() इससे पहले कि आप textView.setText()

textView = (TextView) textEntryView.findViewById(R.id.username_view);

0

करते हैं? आपको सबसे पहले अपने 'टेक्स्ट व्यू' फ़ील्ड को सीर करना चाहिए।

0

TexView पाठ संवाद में है कि पता लगाएं और सेट TextView का मूल पाठ इस link

संबंधित मुद्दे