Note that there are some explanatory texts on larger screens.

plurals
  1. PONPE in Custom DialogBox
    primarykey
    data
    text
    <p>I'm creating a custom dialog box for impliment a voice recorder. In the dialog box, there is 3 buttons, and when i set onclicklistener for these button, it shows force close.</p> <pre><code>eveAdAudio.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mdialog = new Dialog(event_details.this); mdialog.setContentView(R.layout.recorder_dialog); final ViewHolder holder = new ViewHolder(); mdialog.setTitle("Events..."); holder.startRecord = (Button) mdialog.findViewById(R.id.startRecordBtn); holder.stopRecord = (Button) mdialog.findViewById(R.id.stopRecordBtn); holder.saveRecord = (Button) mdialog.findViewById(R.id.saveRecordbtn); holder.showRecord = (TextView) mdialog.findViewById(R.id.recordShowText); holder.nameRecord = (EditText) mdialog.findViewById(R.id.editAudioName); holder.nameRecord.setText("myAudioFile"); holder.startRecord.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub p=1; holder.startRecord.setEnabled(false); holder.stopRecord.setEnabled(true); holder.showRecord.setVisibility(View.VISIBLE); anim = new AlphaAnimation(0.0f, 1.0f); anim.setDuration(800); //You can manage the time of the blink with this parameter anim.setStartOffset(20); anim.setRepeatMode(Animation.REVERSE); anim.setRepeatCount(Animation.INFINITE); holder.showRecord.startAnimation(anim); try { startRecording(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); holder.stopRecord.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub p=2; holder.startRecord.setEnabled(true); holder.saveRecord.setEnabled(true); holder.stopRecord.setEnabled(false); holder.showRecord.clearAnimation(); holder.showRecord.setVisibility(View.INVISIBLE); try { //stopRecording(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } holder.nameRecord.setEnabled(true); } }); holder.saveRecord.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub audioFileName = holder.nameRecord.getText().toString()+".mp4"; p=3; mdialog.dismiss(); } }); mdialog.show(); } }); </code></pre> <p>This is the viewhoder class</p> <pre><code>private class ViewHolder{ Button startRecord; Button stopRecord; Button saveRecord; TextView showRecord; EditText nameRecord; } </code></pre> <p>starRecording and stopRecording functions ae given below.</p> <pre><code>public void startRecording() throws IOException{ recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); audiofile =getFilename(audFolder);//path of file; recorder.setOutputFile(audiofile); recorder.setOnErrorListener(errorListener); recorder.setOnInfoListener(infoListener); try { recorder.prepare(); recorder.start(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void stopRecording() throws Exception { if(null != recorder){ recorder.stop(); recorder.reset(); recorder.release(); recorder = null; } } </code></pre> <p>The layout of custom dialog is given below:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/voice" /&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" android:layout_gravity="center" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" AuFriDis\nVoice Recorder" android:textSize="15dp" android:typeface="serif" android:textStyle="bold|italic" android:layout_marginRight="15dp"/&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" android:layout_gravity="center" &gt; &lt;TextView android:id="@+id/recordShowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Recording..." android:textColor="#ffffff" android:textStyle="bold|italic" android:textSize="15dp" android:visibility="invisible"/&gt; &lt;EditText android:id="@+id/editAudioName" android:layout_width="150dp" android:layout_height="40dp" android:ems="10" android:visibility="invisible"&gt; &lt;/EditText&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginTop="10dp" android:gravity="center"&gt; &lt;Button android:id="@+id/startRecordBtn" android:layout_width="70dp" android:layout_height="40dp" android:textColor="#ff0000" android:background="@drawable/item_background" android:text="Start" android:layout_marginRight="4dp"/&gt; &lt;Button android:id="@+id/stopRecordBtn" android:layout_width="70dp" android:layout_height="40dp" android:textColor="#0066ff" android:background="@drawable/item_background" android:text="Stop" android:layout_marginRight="4dp" android:enabled="false"/&gt; &lt;Button android:id="@+id/saveRecordbtn" android:layout_width="70dp" android:layout_height="40dp" android:textColor="#ffffff" android:background="@drawable/item_background" android:text="Save" android:enabled="false"/&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>The error lines are like these:</p> <pre><code>10-20 22:23:39.155: E/AndroidRuntime(1528): FATAL EXCEPTION: main 10-20 22:23:39.155: E/AndroidRuntime(1528): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.view.ViewRoot.setView(ViewRoot.java:509) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.app.Dialog.show(Dialog.java:241) 10-20 22:23:39.155: E/AndroidRuntime(1528): at MainPRJ.Diary.event_details$6.onClick(event_details.java:353) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.view.View.performClick(View.java:2408) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.view.View$PerformClick.run(View.java:8816) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.os.Handler.handleCallback(Handler.java:587) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.os.Handler.dispatchMessage(Handler.java:92) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.os.Looper.loop(Looper.java:123) 10-20 22:23:39.155: E/AndroidRuntime(1528): at android.app.ActivityThread.main(ActivityThread.java:4627) 10-20 22:23:39.155: E/AndroidRuntime(1528): at java.lang.reflect.Method.invokeNative(Native Method) 10-20 22:23:39.155: E/AndroidRuntime(1528): at java.lang.reflect.Method.invoke(Method.java:521) 10-20 22:23:39.155: E/AndroidRuntime(1528): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 10-20 22:23:39.155: E/AndroidRuntime(1528): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 10-20 22:23:39.155: E/AndroidRuntime(1528): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload