0

I am working with an android app for web view.It contains an image button. On clicking the image button,it will shows a popup window over web view.The popup window contains edit text fields.On clicking submit button the edit text values are send as a mail and the popup will be dismissed. The problem I faced is I cant read edit text values.When it used the app is force closed..How to solve this problem please help me and thanks.

here is my code

        public class WebViewExample extends Activity {
   private WebView mWebView;
   private ImageView image;
   String str5;
    private PopupWindow mpopup;
    ProgressBar progressBar;
    Context context;
    /** Called when the activity is first created. */


     @Override
       public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.main);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    if(isNetworkStatusAvialable (getApplicationContext())) {
        mWebView = (WebView) findViewById(R.id.webview);
         progressBar = (ProgressBar) findViewById(R.id.progressBar1);
         image =(ImageView)findViewById(R.id.image);


            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.setWebViewClient(new wapWebViewClient());
            mWebView.loadUrl("http://facebook.com//");

            mWebView.setWebChromeClient(new WebChromeClient() {
                @Override
                public void onProgressChanged(WebView view, int progress) 
                   {
                   if(progress < 100 && progressBar.getVisibility() == View.GONE){
                       progressBar.setVisibility(View.VISIBLE);

                   }
                   progressBar.setProgress(progress);
                   if(progress == 100) {
                       mWebView.setVisibility(View.VISIBLE);
                       progressBar.setVisibility(View.GONE);
                   }
                   }
               });


         } else {
                 Toast.makeText(getApplicationContext(), "internet is not avialable ", Toast.LENGTH_LONG).show();

            }
              ImageButton   imageButton1 = (ImageButton) findViewById(R.id.imageButton1);
             ImageButton    imageButton2 = (ImageButton) findViewById(R.id.imageButton2);

       imageButton1.setOnClickListener(new OnClickListener() {


            public void onClick(View v) {

               Intent feedbackEmail = new Intent(Intent.ACTION_SEND);

             feedbackEmail.setType("text/email");
             feedbackEmail.putExtra(Intent.EXTRA_EMAIL, new String[] {"prince@gmail.com"});
              feedbackEmail.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
             startActivity(Intent.createChooser(feedbackEmail, "Send Feedback:"));
        }
       });

          imageButton2.setOnClickListener(new OnClickListener() {


             public void onClick(View v) {
               View popUpView = getLayoutInflater().inflate(R.layout.popup, null); // inflating popup layout
               mpopup = new PopupWindow(popUpView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true); //Creation of popup

                 mpopup.showAtLocation(mWebView, Gravity.CENTER, 0, 0);    // Displaying popup
                ImageButton Sub = (ImageButton) popUpView.findViewById(R.id.submit); 
                 EditText t1=(EditText)findViewById(R.id.editText1);
                 EditText t2=(EditText)findViewById(R.id.editText2);
                 EditText t3=(EditText)findViewById(R.id.editText3);

                String str1=t1.getText().toString();
                String str2=t2.getText().toString();
                String str3=t3.getText().toString();
                String str4=t3.getText().toString();
                 str5="name:"+str1+"  "+"email:"+str2+"  "+"number:"+str3+"  "+"idea:"+str4;
                Sub.setOnClickListener(new OnClickListener() {


                public void onClick(View v) {

                    Intent email = new Intent(Intent.ACTION_SEND);

                    email.setType("text/email");
                    email.putExtra(Intent.EXTRA_EMAIL, new String[] {"prince@gmail.com"});
                     email.putExtra(Intent.EXTRA_SUBJECT, "I have an Idea");
                     email.putExtra(Intent.EXTRA_TEXT, str5);  
                       startActivity(Intent.createChooser(email,"Send Your Idea"));

                     mpopup.dismiss();

                }
             }); 
         }
         });

     }

      private void incrementPercentage(){
       int mProgressStatus=0;
       mProgressStatus++;//i declared it as a private Integer on the activity class.
       progressBar.setProgress(mProgressStatus);
     }



       public static boolean isNetworkStatusAvialable (Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
             if (connectivityManager != null) 
       {
            NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
            if(netInfos != null)
            if(netInfos.isConnected()) 
               return true;
        }
       return false;
   }

        private class wapWebViewClient extends WebViewClient {

     @Override
       public boolean shouldOverrideUrlLoading(WebView view, String url) {
     // view.loadUrl(url);
          return false;
      }

     @Override
        public void onPageFinished(WebView view, String url) {
      // when the page loaded splash screen has been invisible
     // mWebView.setVisibility(View.VISIBLE);   
      progressBar.setVisibility(View.GONE);
      image.setVisibility(View.GONE);

     }

        @Override
        public void onReceivedError(WebView view, int errorCode,
               String description, String failingUrl) {
          // if any error occured this message will be showed
             Toast.makeText(WebViewExample.this, "Error is occured, please try again..." + description, Toast.LENGTH_LONG).show();
       }
     }

      @Override
         public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
          // setting of back button
      mWebView.goBack();
             return true;
           }
           return super.onKeyDown(keyCode, event);
          }
        }

here is y xml

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:orientation="vertical" >

    <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/name"
    android:layout_alignLeft="@+id/editText2"
    android:layout_alignParentTop="true"
    android:layout_marginTop="42dp"
    android:ems="10" />

   <EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:ems="10"
    android:hint="@string/email" />

    <EditText
    android:id="@+id/editText3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText2"
    android:layout_below="@+id/editText2"
    android:layout_marginTop="19dp"
    android:ems="10"
    android:hint="@string/phone" />




   <EditText
    android:id="@+id/editText4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText3"
    android:layout_below="@+id/editText3"
    android:layout_marginTop="34dp"
    android:ems="10"
    android:hint="@string/idea"
    android:inputType="textMultiLine" />

   <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/submit"
    android:layout_marginRight="16dp"
    android:layout_marginTop="15dp"
    android:text="@string/hading" />

   <ImageButton
    android:id="@+id/submit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText4"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="43dp"
    android:background="@null"
    android:src="@drawable/submit" />

  </RelativeLayout>

new xml

    <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:orientation="vertical" >

    <EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:hint="@string/name"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="48dp"
    android:ems="10" />

   <EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/email"
    android:layout_alignLeft="@+id/editText1"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="30dp"
    android:ems="10" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/phone"
    android:layout_alignLeft="@+id/editText2"
    android:layout_below="@+id/editText2"
    android:layout_marginTop="30dp"
    android:ems="10" />



<EditText
    android:id="@+id/editText4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText3"
    android:hint="@string/idea"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="31dp"
    android:ems="10"
    android:inputType="textMultiLine" />

<ImageButton
    android:id="@+id/submit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="51dp"
    android:src="@drawable/submit" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="72dp"
    android:text="@string/hading" />

     </RelativeLayout>

1 Answers1

1

Mistakes I could get from code:

Replace

EditText t1=(EditText)findViewById(R.id.editText1);
EditText t2=(EditText)findViewById(R.id.editText2);
EditText t3=(EditText)findViewById(R.id.editText3);

with

EditText t1=(EditText)popUpView.findViewById(R.id.editText1);
EditText t2=(EditText)popUpView.findViewById(R.id.editText2);
EditText t3=(EditText)popUpView.findViewById(R.id.editText3);

You are getting null in those edittexts. ecause those views are in popu and you are trying to get them from main activity.

And the values of edittexts should be retrieved in strings in onClick of dialog's submit as:

Sub.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

        String str1=t1.getText().toString();
        String str2=t2.getText().toString();
        String str3=t3.getText().toString();
        String str4=t3.getText().toString();
        str5="name:"+str1+"  "+"email:"+str2+"  "+"number:"+str3+"  "+"idea:"+str4;

        //Email intent goes here...
    }
});

Hope this helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
  • thank u sir.now the problem is solved...I have one more dbt...how can the popup make to fullscreen ?? –  Jan 16 '14 at 05:29
  • @doubter you can set the width and height to match_parent in xml of popup. – MysticMagicϡ Jan 16 '14 at 05:43
  • Try changing `mpopup = new PopupWindow(popUpView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true); //Creation of popup` to `mpopup = new PopupWindow(popUpView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, true); //Creation of popup` @doubter – MysticMagicϡ Jan 16 '14 at 06:29
  • it wrks but now i just change the layout ...now it is force closed..i just change the position of edittext and image button... –  Jan 16 '14 at 06:37
  • @doubter please post logcat output. – MysticMagicϡ Jan 16 '14 at 06:44
  • @doubter If there is a force close, then you must be getting some output in logcat. – MysticMagicϡ Jan 16 '14 at 06:56