这是我的OnpreferenceListener
。我在警报对话框中使用自定义布局并尝试在自定义布局中找到单击。在方法上获取空指针异常OnClickListener
。谁能指出这里出了什么问题?
sendus_feedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
ContextThemeWrapper wrapper = new ContextThemeWrapper(SettingsActivity.this,
android.R.style.Theme_Holo_Light);
@SuppressWarnings("unused")
final LayoutInflater inflater = (LayoutInflater) wrapper
.getSystemService(LAYOUT_INFLATER_SERVICE);
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(wrapper);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View feedbackView = layoutInflater.inflate(R.layout.rate_now_layout, null);
myAlertDialog.setView(feedbackView);
ImageView ratenow = (ImageView) feedbackView
.findViewById(R.drawable.rate_now);
ratenow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.v("clicked ratenow", "yes");
Uri uri = Uri.parse("market://details?id="
+ getApplicationContext()
.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(),
"Couldn't launch the market",
Toast.LENGTH_LONG).show();
}
}
});
myAlertDialog.setPositiveButton("No, thanks.",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0,
int arg1) {
}
});
myAlertDialog.setNegativeButton("Ask me later",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0,
int arg1) {
}
});
myAlertDialog.show();
return false;
}
});