加载数据后不显示列表,但关闭显示并显示列表时
list is not displayed after loading the data but when the display is turned off and on list is displayed
加载数据后不显示列表视图,但当屏幕显示关闭并打开列表时 displayed.don不知道是什么 happening.i 我正在使用小米小米 phone测试应用程序是否需要任何其他活动代码,请告诉我
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class FriendList extends ListActivity {
String email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
email = bundle.getString("email");
setContentView(R.layout.contacts_list);
final List<Model> list = new ArrayList<Model>();
/** This block is for getting the image url to download from the server **/
final GetDataFromDB getvalues = new GetDataFromDB();
final ProgressDialog dialog = ProgressDialog.show(FriendList.this,
"", "Gettting values from DB", true);
new Thread (new Runnable() {
public void run() {
String response = getvalues.getImageURLAndDesciptionFromDB(email);
System.out.println("Response : " + response);
if (!response.equalsIgnoreCase("")) {
if (!response.equalsIgnoreCase("error")) {
dismissDialog(dialog);
// Got the response, now split it to get the image Urls and description
String all[] = response.split("\|::endline::\|");
for(int k = 0; k < all.length; k++){
String urls_and_desc[] = all[k].split("\|::break::\|"); // urls_and_desc[0] contains image url and [1] -> description
System.out.println("image url : " + urls_and_desc[2]);
list.add(get(urls_and_desc[1], "https://xxxx.xx/" + urls_and_desc[2]));
}
}
} else {
dismissDialog(dialog);
}
}
}).start();
/*************************** GOT data from Server ********************************************/
ArrayAdapter<Model> adapter = new MyCustomArrayAdapter(this, list);
adapter.notifyDataSetChanged();
setListAdapter(adapter);
}
public void dismissDialog(final ProgressDialog dialog){
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
}
});
}
private Model get(String s, String url) {
return new Model(s, url);
}
}
您应该在从服务器获取数据后调用 ((ArrayAdapter<Model>)getListAdapter()).notifyDataSetChanged()
:
new Thread (new Runnable() {
public void run() {
String response = getvalues.getImageURLAndDesciptionFromDB(email);
System.out.println("Response : " + response);
if (!response.equalsIgnoreCase("")) {
if (!response.equalsIgnoreCase("error")) {
dismissDialog(dialog);
// Got the response, now split it to get the image Urls and description
String all[] = response.split("\|::endline::\|");
for(int k = 0; k < all.length; k++){
String urls_and_desc[] = all[k].split("\|::break::\|"); // urls_and_desc[0] contains image url and [1] -> description
System.out.println("image url : " + urls_and_desc[2]);
list.add(get(urls_and_desc[1], "https://xxxx.xx/" + urls_and_desc[2]));
}
runOnUiThread(new Runnable() {
@Override
public void run() {
((ArrayAdapter<Model>)getListAdapter()).notifyDataSetChanged();//Notify ListView to update itself.
}
});
}
} else {
dismissDialog(dialog);
}
}
}).start();
加载数据后不显示列表视图,但当屏幕显示关闭并打开列表时 displayed.don不知道是什么 happening.i 我正在使用小米小米 phone测试应用程序是否需要任何其他活动代码,请告诉我
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class FriendList extends ListActivity {
String email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
email = bundle.getString("email");
setContentView(R.layout.contacts_list);
final List<Model> list = new ArrayList<Model>();
/** This block is for getting the image url to download from the server **/
final GetDataFromDB getvalues = new GetDataFromDB();
final ProgressDialog dialog = ProgressDialog.show(FriendList.this,
"", "Gettting values from DB", true);
new Thread (new Runnable() {
public void run() {
String response = getvalues.getImageURLAndDesciptionFromDB(email);
System.out.println("Response : " + response);
if (!response.equalsIgnoreCase("")) {
if (!response.equalsIgnoreCase("error")) {
dismissDialog(dialog);
// Got the response, now split it to get the image Urls and description
String all[] = response.split("\|::endline::\|");
for(int k = 0; k < all.length; k++){
String urls_and_desc[] = all[k].split("\|::break::\|"); // urls_and_desc[0] contains image url and [1] -> description
System.out.println("image url : " + urls_and_desc[2]);
list.add(get(urls_and_desc[1], "https://xxxx.xx/" + urls_and_desc[2]));
}
}
} else {
dismissDialog(dialog);
}
}
}).start();
/*************************** GOT data from Server ********************************************/
ArrayAdapter<Model> adapter = new MyCustomArrayAdapter(this, list);
adapter.notifyDataSetChanged();
setListAdapter(adapter);
}
public void dismissDialog(final ProgressDialog dialog){
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
}
});
}
private Model get(String s, String url) {
return new Model(s, url);
}
}
您应该在从服务器获取数据后调用 ((ArrayAdapter<Model>)getListAdapter()).notifyDataSetChanged()
:
new Thread (new Runnable() {
public void run() {
String response = getvalues.getImageURLAndDesciptionFromDB(email);
System.out.println("Response : " + response);
if (!response.equalsIgnoreCase("")) {
if (!response.equalsIgnoreCase("error")) {
dismissDialog(dialog);
// Got the response, now split it to get the image Urls and description
String all[] = response.split("\|::endline::\|");
for(int k = 0; k < all.length; k++){
String urls_and_desc[] = all[k].split("\|::break::\|"); // urls_and_desc[0] contains image url and [1] -> description
System.out.println("image url : " + urls_and_desc[2]);
list.add(get(urls_and_desc[1], "https://xxxx.xx/" + urls_and_desc[2]));
}
runOnUiThread(new Runnable() {
@Override
public void run() {
((ArrayAdapter<Model>)getListAdapter()).notifyDataSetChanged();//Notify ListView to update itself.
}
});
}
} else {
dismissDialog(dialog);
}
}
}).start();