我在互联网上搜索过,但出于某种原因,我还没有找到这段代码。我正试图通过HttpGet请求从我的服务器获取字符串和一些图像,然后我将数据放入我的列表视图中。
我该怎么做?我已经尝试了所有的东西,我可以粘贴我的代码,但它不起作用,所以它没有多大帮助。
那么,如何通过httpGet请求获取数据,然后将收到的数据放入列表视图中。
感谢。
public class ChatService extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chatservice);
ContactsandIm();
ListView list = (ListView) findViewById(R.id.ListView01);
list.setClickable(true);
final List<PhoneBook> listOfPhonebook = new ArrayList<PhoneBook>();
listOfPhonebook.add(new PhoneBook(a, "9981728", "test@test.com"));
listOfPhonebook
.add(new PhoneBook("Test1", "1234455", "test1@test.com"));
listOfPhonebook.add(new PhoneBook("Test2", "00000", "test2@test.com"));
PhonebookAdapter adapter = new PhonebookAdapter(this, listOfPhonebook);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view,
int position, long index) {
System.out.println("sadsfsf");
showToast(listOfPhonebook.get(position).getName());
}
});
list.setAdapter(adapter);
}
private void ContactsandIm() {
// TODO Auto-generated method stub
HttpGet a = new HttpGet("http://www.gta5news.com/getdata.php");
}
// end bracket for "ContactsandIm"
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}