Hier ist mein Code für eine Tätigkeit ist, die einen benutzerdefinierten Dialogfeld in sich einbettet:Dialog Benutzerdefinierte Box kann nicht geschlossen werden
package com.example.hotel_app_regularuser;
import android.animation.ObjectAnimator;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
public class GetUserPreference extends Activity implements Runnable {
TextView tv,tr;
Button bt;
Thread t1;
Dialog d;
ObjectAnimator textColorAnim;
LinearLayout lyt,lyt2;
PopupWindow popUp;
LayoutParams params;
Button cbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_user_preference);
tv=(TextView)findViewById(R.id.textView1);
lyt= (LinearLayout) findViewById(R.id.LinearLayout1);
lyt2=new LinearLayout(this);
popUp = new PopupWindow(this);
t1=new Thread(this);
cbutton=(Button)findViewById(R.id.closebutton);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/rs.ttf");
Intent it=getIntent();
String a=it.getStringExtra("username");
tv.setText("Welcome"+" "+a);
tv.setTypeface(type);
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,50);
tv.setTextColor(Color.RED);
d = new Dialog(this);
bt=(Button)findViewById(R.id.button1);
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
// bt.startAnimation(animation);
bt.startAnimation(animation);
d.setContentView(R.layout.customxml);
d.setTitle("welcome");
TextView t = (TextView)d.findViewById(R.id.textView1);
t.setText("hiii");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.get_user_preference, menu);
return true;
}
public void go(View vw)
{
d.show();
}
public void rempopup(View v)
{
d.dismiss();
}
@Override
public void run(){}
}
Hier ist meine customxml.xml Datei
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/closebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="rempopup"/>
</LinearLayout>
Problem ist Wenn ich auf die Schaltfläche im benutzerdefinierten Dialogfeld klicke, wird meine App abrupt geschlossen. Die Entlassung() wird aus irgendeinem Grund nicht aufgerufen. Bitte helfen
Hier ist mein Crashlog
07-04 10:57:29.340: E/AndroidRuntime(19455): FATAL EXCEPTION: main
07-04 10:57:29.340: E/AndroidRuntime(19455): Process: com.example.hotel_app_regularuser, PID: 19455
07-04 10:57:29.340: E/AndroidRuntime(19455): java.lang.IllegalStateException: Could not find a method rempopup(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'closebutton'
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.view.View$1.onClick(View.java:4034)
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.view.View.performClick(View.java:4802)
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.view.View$PerformClick.run(View.java:20101)
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.os.Handler.handleCallback(Handler.java:810)
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.os.Looper.loop(Looper.java:189)
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.app.ActivityThread.main(ActivityThread.java:5532)
07-04 10:57:29.340: E/AndroidRuntime(19455): at java.lang.reflect.Method.invoke(Native Method)
07-04 10:57:29.340: E/AndroidRuntime(19455): at java.lang.reflect.Method.invoke(Method.java:372)
07-04 10:57:29.340: E/AndroidRuntime(19455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
07-04 10:57:29.340: E/AndroidRuntime(19455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
07-04 10:57:29.340: E/AndroidRuntime(19455): Caused by: java.lang.NoSuchMethodException: rempopup [class android.view.View]
07-04 10:57:29.340: E/AndroidRuntime(19455): at java.lang.Class.getMethod(Class.java:664)
07-04 10:57:29.340: E/AndroidRuntime(19455): at java.lang.Class.getMethod(Class.java:643)
07-04 10:57:29.340: E/AndroidRuntime(19455): at android.view.View$1.onClick(View.java:4027)
07-04 10:57:29.340: E/AndroidRuntime(19455): ... 10 more
Bitte posten Sie Ihre Crash-Protokoll. –
wie Sie diese Methode aufrufen 'rempopup()' –
versucht mit XML .. aber es hat nicht funktioniert .. –