【发布时间】:2015-10-09 03:15:40
【问题描述】:
在将数据加载到ListView 后,我试图隐藏ProgressBar。但是,ProgressBar 似乎不受视图更改的影响。我没有收到任何错误(activityIndicator 似乎不是NULL)。我的处理方式有问题吗?
<ProgressBar
android:id="@+id/activityIndicator"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:indeterminateOnly="true"
android:keepScreenOn="true"
android:layout_gravity="center" />
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
theInflater = inflater;
theContainer = container;
currentView = inflater.inflate(R.layout.fragment_server_list, container, false);
activityIndicator = (ProgressBar) currentView.findViewById(R.id.activityIndicator);
// check if you are connected or not
if(isConnected()){
new Thread(new Runnable() {
public void run() {
HashMap<String, String> data = new HashMap<String, String>();
data.put("action", "getServerList");
data.put("phone_id", "857a95839d7d6c270e97ff6a3a64008ccf96074ebffa6e8e82db932a6c635644");
data.put("username", "atomic");
data.put("password", "Pa55word1");
AsyncHttpPost asyncHttpPost = new AsyncHttpPost(data);
try {
String jsonString = asyncHttpPost.execute("http://website.com/app-files/API.php").get();
Log.i("JSON Result", jsonString);
try {
JSONObject json = new JSONObject(jsonString);
if (json.optString("result").equalsIgnoreCase("true")) {
JSONArray articles = json.getJSONArray("data");
for (int i = 0; i < articles.length(); i++) {
JSONObject row = articles.getJSONObject(i);
myServers.add(new Server(Integer.parseInt(row.getString("id")),
row.getString("host"),
0, //Integer.parseInt(row.getString("port")),
"", //row.getString("hostname"),
"", //row.getString("ipAddress"),
"", //row.getString("checkDate"),
"", //row.getString("serverInfo"),
"", //row.getString("lastModified"),
"", //row.getString("contentType"),
"", //row.getString("city"),
"", //row.getString("state"),
"", //row.getString("zip"),
"", //row.getString("country"),
"", //row.getString("latitude"),
"", //row.getString("longitude"),
"", //row.getString("timeZone"),
0, //Integer.parseInt(row.getString("consecutiveFails")),
Float.parseFloat(row.getString("latency")),
Float.parseFloat(row.getString("latency")) > 300 ?
R.drawable.btn_yellow : (Float.parseFloat(row.getString("latency")) > 1 ?
R.drawable.btn_green : R.drawable.btn_red)));
//Log.i("Current Server's Host", row.getString("host"));
}
populateListView();
registerClickCallback();
currentView.post(new Runnable() {
public void run() {
activityIndicator.setVisibility(View.INVISIBLE);
}
});
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
activityIndicator.setVisibility(View.GONE);
}else{
Log.i("Connection", "You are NOT connected");
}
return currentView;
}
编辑:似乎如果我离开选项卡并返回此视图的选项卡,进度条就消失了。所以这就好像它正在移除进度条,但视图没有更新以显示它已被审核。
【问题讨论】:
-
您的应用程序是否关闭?
-
您在启动线程后立即隐藏 ProgressBar,也在线程内部。您确定这种行为吗?
-
@Rod_Algonquin 不,应用程序不会崩溃。它很好地显示了我的列表视图,我可以滚动和单击。它唯一没有做的就是隐藏进度条。
-
@AbhishekShukla 是的,我确定。我只是想让它隐藏起来。之后,我只能在需要时让它隐藏起来。但不幸的是,它根本没有隐藏。
-
在 xml 中放置进度条是个坏主意。最好动态创建一个。
标签: android android-progressbar