我幾乎在所有的類中都有這種方法。靜態成員被實例引用訪問的最佳解決方案
//listener - info
private void clickInfoListener(final ImageView iv, final int title, final int text){
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
materialHelper.showInfoDialog(MainActivity.this, iv, title, text);
}
});
}
在輔助類
public static void showInfoDialog(Context context, final ImageView iv, final int title, final int text){
iv.setImageResource(R.drawable.ic_info_touched);
//
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(text);
builder.setPositiveButton(R.string.gotIt, null);
builder.show();
//
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
iv.setImageResource(R.drawable.ic_info_primary);
}
}, 25);
}
我得到的「靜態成員被實例引用訪問」 lint警告的訪問這個靜態方法。我不知道如何在這裏不使用「this」。所以我有兩個選擇。
1)忽略lint警告
2)刪除了 「靜態」 在我的helper方法。
哪個更好?或者提出第三種解決方案。
真棒!將在5分鐘內接受。 – seekingStillness