我正在尝试将我的应用对话添加到我的应用中但是在Dialouge.OnClickListener中它要求查看。 怎么解决这个问题?
public class AppRater {
private final static String APP_TITLE = "YOUR-APP-NAME";
private final static String APP_PNAME = "YOUR-PACKAGE-NAME";
private final static int DAYS_UNTIL_PROMPT = 3;
private final static int LAUNCHES_UNTIL_PROMPT = 7;
public static void app_launched(Context mContext) {
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
if (prefs.getBoolean("dontshowagain", false)) { return ; }
SharedPreferences.Editor editor = prefs.edit();
// Increment launch counter
long launch_count = prefs.getLong("launch_count", 0) + 1;
editor.putLong("launch_count", launch_count);
// Get date of first launch
Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
if (date_firstLaunch == 0) {
date_firstLaunch = System.currentTimeMillis();
editor.putLong("date_firstlaunch", date_firstLaunch);
}
// Wait at least n days before opening
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= date_firstLaunch +
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
showRateDialog(mContext, editor);
}
}
editor.commit();
}
public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
final Dialog dialog = new Dialog(mContext);
dialog.setTitle("Rate " + APP_TITLE);
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(mContext);
tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
tv.setWidth(240);
tv.setPadding(4, 0, 4, 10);
ll.addView(tv);
Button b1 = new Button(mContext);
b1.setText("Rate " + APP_TITLE);
b1.setOnClickListener(new DialogInterface.OnClickListener() {
public void onClick(View v) {
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
dialog.dismiss();
}
});
ll.addView(b1);
Button b2 = new Button(mContext);
b2.setText("Remind me later");
b2.setOnClickListener(new DialogInterface.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
ll.addView(b2);
Button b3 = new Button(mContext);
b3.setText("No, thanks");
b3.setOnClickListener(new DialogInterface.OnClickListener() {
public void onClick(View v) {
if (editor != null) {
editor.putBoolean("dontshowagain", true);
editor.commit();
}
dialog.dismiss();
}
});
ll.addView(b3);
dialog.setContentView(ll);
dialog.show();
}
}
错误仅显示在(查看v)其他一切都很好。
我尝试将DialogInterface.OnClickListener
更改为View.OnClickListener
,但这也无效。
答案 0 :(得分:0)
你能不能正确地寻找: 根据我的网站我认为你想要的方法调用时,你想要一个带有两个按钮和一个评级栏的对话框。 按钮:确定并取消 评级栏: 创建一个名为ccc.xml ::
的xml<?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:background="#ffffee"
android:orientation="vertical"
android:theme="@style/AppTheme.NoActionBar"
>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rate"
android:id="@+id/rate"
android:layout_weight="1"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remind me Late"
android:id="@+id/later"
android:layout_weight="1"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Thanks.."
android:layout_weight="1"
android:id="@+id/no" />
</LinearLayout>
然后将其写入您想要的地方:
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog d=new Dialog(MainActivity.this);
d.setContentView(R.layout.ccc);
d.show();
RatingBar rate=(RatingBar)d.findViewById(R.id.ratingBar);
Button rt=(Button)d.findViewById(R.id.rate);
Button later=(Button)d.findViewById(R.id.later);
Button no=(Button)d.findViewById(R.id.no);
rate.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
//do here what & where you want to save the rating
}
});
rt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do what you want on rate button
}
});
later.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do what you want on Remind me later button
}
});
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// do what you want on NO button
}
});
}
});
如果您需要任何更改,请回复...