我试图在actionBar上放置一个不确定的ProgressBar.我使用actionView将progressBar设置为Google+应用程序,例如.
<item
android:id="@+id/menu_progress"
android:actionLayout="@layout/action_progress"
android:menuCategory="container"
android:showAsAction="always">
</item>
Run Code Online (Sandbox Code Playgroud)
问题是进度条被视为一个项目,因此在Nexus S纵向模式下,我在操作栏上只有一个其他项目,而在Google+上我可以看到两个项目加上progressBar.如何使用android操作栏放置进度条?
我到处搜索并阅读谷歌的官方文档.但我仍然没有看到它们之间的区别.
我们应该何时使用ProgressBar,何时应该使用ProgressDialog?
我想在listview加载时显示ProgressDialog.我已经尝试过如下编码,但它没有用.
final ProgressDialog dialog = ProgressDialog.show(this, "indeterminate", "Please wait while loading", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
dialog.dismiss();
}
};
Thread checkUpdate = new Thread() {
public void run() {
// listview will be populated here
PopulateListView();
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
Run Code Online (Sandbox Code Playgroud)
但它根本不起作用.
是否可以向ActionBarSherlock添加进度条?我需要在特定时间显示和隐藏它.但它必须位于ActionBarSherlock内.
我班的代码.你可以看到,我使用requestWindowFeature(Window.FEATURE_PROGRESS),但它没有任何区别.同样的结果.:
public class RecipeActivity extends SherlockActivity {
private String picture;
private String TAG = "RecipeActivity";
private ImageView viewPicture;
private RecipeGeneral recipeGeneral;
private Recipe recipe;
private String [] pictures;
private ArrayList<Step> steps;
//private ImageView viewStar;
private DataBaseFactory db;
private NyamApplication application;
private TextView viewDescription;
private TextView userView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
try {
setContentView(R.layout.recipe_page);
getSupportActionBar().setDisplayShowTitleEnabled(false);
recipeGeneral = (RecipeGeneral)getIntent().getSerializableExtra("Recipe");
Log.d(TAG, "recipeGeneral = " + recipeGeneral.toString());
picture = Constants.URL + recipeGeneral.getImg_url();
Log.d(TAG,"picture : " + picture);
viewPicture …Run Code Online (Sandbox Code Playgroud) 在我的列表视图没有填充数据库数据时,有什么更好的方法来显示进度指示器?
我找到了一些如何使用assynctask执行此操作的示例,但在我的情况下,我使用Loader/ CursorLoader.
public class TestActivity extends SherlockFragmentActivity implements
LoaderCallbacks<Cursor> {
SimpleCursorAdapter mAdapter;
ListView mListView;
private static final String[] UI_BINDING_FROM = new String[] {
TestDBAdapter.KEY_NAME, TestDBAdapter.KEY_ICON };
private static final int[] UI_BINDING_TO = new int[] { R.id.text, R.id.icon };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_Test);
mListView = (ListView) findViewById(R.id.listview);
mAdapter = new TestAdapter(getApplicationContext(),
R.layout.list_item_Test, null, UI_BINDING_FROM,
UI_BINDING_TO, 0);
mListView.setAdapter(mAdapter);
getSupportLoaderManager().initLoader(0, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri uri = ContentProviderTest.CONTENT_URI; …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中添加ListView,在LinearLayout加载时,而不是列表有进度条.这类似于系统应用程序,您可以在其中管理您的应用程序.
我找到了一些关于它的信息,但没有一个是好的.看起来最好的一个就是创建两个布局(一个带有进度条,另一个带有ListView),然后onPreExecute()(我AsyncTask用于此)显示进度条.然后onPostExecute()隐藏它,这就是全部.
我试图实现它,但我有ScrapView错误,没有更多的信息,它是如何做到的.
所以,我的问题是,你会怎么建议我这样做?我不想要任何进度对话框.
编辑:
这是我的代码片段,显示了我到目前为止所做的事情:
TestActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylist_layout);
wordList = (ListView) findViewById(R.id.wordsList);
//...
}
private class AsyncDBDownload extends AsyncTask<String, Integer, String> {
LinearLayout linlaHeaderProgress = (LinearLayout) findViewById(R.id.linlaHeaderProgress);
@Override
protected String doInBackground(String... params) {
try {
refreshList();//upload of contetn and set of adapter
} catch (Exception ex) {
Log.e(TAG, ex.toString());
}
return null;
}
@Override
protected void onPostExecute(String result) {
linlaHeaderProgress.setVisibility(View.GONE);
wordList.setVisibility(View.VISIBLE);
} …Run Code Online (Sandbox Code Playgroud)