如果我們從EditText收到輸入號碼。我們如何創建許多ProgressBars?例如,如果輸入爲5.應創建5個progressBar小部件。如何在Android中輸入任意數量的ProgressBars?
0
A
回答
0
//Progress bar array.
final ProgressBar[] bars = new ProgressBar[numTAs+1];
//Create and initialize the Progress Bar array.
for(int i = 0; i < numTAs + 1; i++){
//ProgressBar bar = new ProgressBar(this);
int style = android.R.style.Widget_ProgressBar_Horizontal;
ProgressBar bar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
bars[i] = bar;
}
//Build Adapter
ArrayAdapter<ProgressBar> adapter = new ArrayAdapter<ProgressBar>(this, R.layout.layout, bars){
@Override
public View getView(int position, View convertView, ViewGroup parent){
return bars[position];
}
};
ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(adapter);
}
+1
請添加一些關於您自己的答案的描述。 –
1
- 在你activity_main.xml中添加的LinearLayout內滾動視圖
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</ScrollView>
在MainActivity.java添加此代碼添加progressBar to linearLayout
int wantedNumber = 5; //get that number from the editText. for (int i = 0; i < wantedNumber; i++) { ProgressBar bar = new ProgressBar(this); bar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); LinearLayout linearLayout; linearLayout.addView(bar); }
我只提到了重要的部分讓我知道,如果你遇到任何問題。
+0
我似乎無法使滾動條出現 –
相關問題
- 1. Postgresql:在數組中搜索任意數量的輸入
- 2. 如何存儲來自用戶的任意數量的輸入?
- 3. 如何在MySQL中加入任意數量的表?
- 4. 輸入任意次數
- 5. 從標準輸入中讀取任意數量的行
- 6. 如何讓用戶從控制檯輸入任意數量的變量
- 7. 添加任意數量的輸入字段的組件?
- 8. 驗證任意數量的輸入字段的形式
- 9. 在CSS任意數量的
- 10. 任意數量
- 11. 如何在VB.NET中舍入到任意數量的小數(即從3.32到3.30)?
- 12. SQL Server:加入任意數量的列
- 13. 如何在C++中使用任意數量的輸入使用映射或矢量進行記憶?
- 14. 如何在任意步驟中輸入工作流程
- 15. 在AngularJS中綁定到(和總計)任意數量的輸入值
- 16. 如何高效加入任意數量的RDD?
- 17. LibreOffice Calc:任意輸入
- 18. 如何在gridview單元格中插入任意數量的鏈接?
- 19. 如何在Julia Plots中創建任意數量的子圖
- 20. 如何在python中並行迭代任意數量的文件?
- 21. 如何在django模型中存儲任意數量的字段?
- 22. 在0.9.5中輸入任何輸入的函數
- 23. 如何在Java中調用任何具有任意數量的參數和任何數據類型的方法
- 24. 任意數量的grid.arrange
- 25. 如何在兩個輸入框中的任意一個輸入框中有輸入時自動將輸入框的值設置爲相反的數字?
- 26. 案例讀取輸入參數是特定的字母或任意數量的
- 27. 如何僅從任意輸入文件中提取字母詞
- 28. 如何從字符串輸入中獲取任意長度的整數
- 29. 在Android中向EXIF寫入任意元數據
- 30. 如何將任意數量的任意類型的數組存儲在字典中
你可以創建線性佈局並添加你想要的數字。 – humazed
請您詳細說明一下嗎? –