在listview Android中显示回显数据

时间:2014-11-27 14:58:31

标签: php android android-listview httpclient

所以,当我尝试在列表视图中显示它时,我的php文件回显了由\ n格式分隔的数据列表,它将整个内容视为android中的单个列表项。如何告诉我的listadapter在xx位置考虑一个新元素,因为我的android代码中没有循环。

<?php 
$query="SELECT * FROM `safa_offers` ORDER BY id DESC ";
    $result = mysql_query($query) or die(mysql_error());



while($row = mysql_fetch_assoc($result))

                                        {
    echo  "Offer Name\n".$row['offer_name']. " \n \n "."Start Date :\n".$row['offer_start']."\n \n"."End Date \n".$row['offer_end']."\n \n"."Details: \n".$row['offer_description']."\n\n";
                                        }

 mysql_close($cn);
 exit();

 ?>

机器人:

void login(){
    try{            

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://agfsrg/Offers.php");
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = httpclient.execute(httppost, responseHandler);

        //This is the response from a php application
        final String reverseString = response;
        //offers.setText(reverseString);
        //Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();


        runOnUiThread(new Runnable() {
            public void run() {
                //offers.setText(reverseString);
                listAdapter.add( reverseString );
                dialog.dismiss();
            }
        });

1 个答案:

答案 0 :(得分:0)

你不能在换行符上拆分字符串吗?您可以使用数组类中的asList函数,因为split返回一个数组。见http://developer.android.com/reference/java/util/Arrays.html#asList(T...)。这是你在找什么?