嗨,大家好我很難搞清楚爲什麼我的按鈕不會顯示正確的文本和顯示垃圾代碼。我正在運行serverRequest,然後在獲取細節後創建按鈕,我確實測試了我從服務器獲取正確的字符串。添加一組按鈕到ListView,然後設置適配器和設置按鈕文本
public void getCourses(User user) {
ServerRequest serverRequest = new ServerRequest(this);
serverRequest.fetchUserCoursesDataInBackground(user, new getUserCallback() {
@Override
public void doneString(String[] returnedString) {
if (returnedString == null) {
System.out.println("DONE EMPTY");
} else {
userLocalStore.storeUserCourses(returnedString);
final ListView listView = (ListView) findViewById(R.id.viewCourseList);
final ArrayList<Button> list = new ArrayList<>();
View v = getWindow().getDecorView();
for (int i = 0; i < returnedString.length; i++) {
System.out.println("This is in for loop:" +returnedString[i]);
Button button = new Button(v.getContext());
button.setText(returnedString[i]);
button.setId(i);
button.setHeight(40);
button.setWidth(100);
list.add(button);
}
if (list.isEmpty()) {
System.out.println("List is empty bro");
} else {
final ArrayAdapter adapter = new ArrayAdapter(v.getContext(), android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter);
System.out.println("Adding adapter");
}
}
}
這是整個代碼。我會告訴你它是什麼應用
你試過把硬編碼的字符串放進去嗎? button.settext( 「foobar的」); – CantThinkOfAnything
@CantThinkOfAnything剛剛嘗試過。沒有改變同樣的事情。 – Serj
難道你是在使用錯誤的上下文嗎? – CantThinkOfAnything