2013-06-27 23 views
-4

我得到關於按鈕android的名稱定義字符串的問題?定義按鈕android名稱的字符串?

//Initial name button 
Button btn_favorite = (Button) findViewById(R.id.btn_favorite); 

//condition 
String Count_Favorite = "Count favorite"; 

//replace string for define name btn_favorite 
String name_btn = Count_Favorite .replace("Count ", "btn_"); 

//(this, name_btn) this part i get problem    
BadgeView badge = new BadgeView(this, name_btn); 
badge.setText("0"); 
badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT); 
badge.show(); 

大膽的是我的問題>>

BadgeView badge = new BadgeView(this, **name_btn**); 
在我的代碼 name_btn

是字符串格式,我會定義爲這個按鈕的名字btn_favorite,而是錯誤。

那麼如何定義字符串name_btn的按鈕btn_favorite

編碼錯誤的這個形象,我的FPGA實現:

enter image description here

BadgeView是這樣

enter image description here

檢查這個>>https://github.com/jgilfelt/android-viewbadger

+2

非常不清楚!請詳細說明.. – CRUSADER

+0

這個不是我的代碼不清楚,請告訴我... – bukanamay

+0

你到底想幹什麼?什麼是'納瑪'? –

回答

0

解決

與此代碼

int id = getResources().getIdentifier(nama_btn, "id", context.getPackageName()); 
View view = findViewById(id); BadgeView badge = new BadgeView(this, view); 
0

從構造函數BadgeView,如果您看到,第二個參數是View,而不是String

public BadgeView(Context context, View target) { 

    this(context, null, android.R.attr.textViewStyle, target, 0); 

} 

請檢查並相應地修改您的代碼。您傳遞String對象作爲BadgeView的參數。