2014-12-04 33 views
3

我想创建一个类似Facebook的新闻源的应用程序它将成为一个文本下方的图像,打开一个新的页面,但我实际上不知道它是什么,所以我无法搜索互联网我不知道它是什么名字,所以如果有人能告诉我它叫什么或者如何制作像Facebook这样的新闻提要或者这个想法的教程。如何制作像android的新闻提要?

回答

3

您必须阅读关于ListViewListAdapter。根据他们的解决方案。

0

我给你一个选择,而第一步。您可以通过JSON使用请求来搜索存储在Web上的文本和图像。

// DownloadJSON AsyncTask 
    private class DownloadJSON extends AsyncTask<Void, Void, Void> { 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      // Create a progressdialog 
      mProgressDialog = new ProgressDialog(MainActivity.this); 
      // Set progressdialog title 
      mProgressDialog.setTitle("Your app"); 
      // Set progressdialog message 
      mProgressDialog.setMessage("Loading..."); 
      mProgressDialog.setIndeterminate(false); 
      // Show progressdialog 
      mProgressDialog.show(); 

     } 

     @Override 
     protected Void doInBackground(Void... params) { 


      // Create an array 
      arraylist = new ArrayList<HashMap<String, String>>(); 
      // Retrieve JSON Objects from the given URL address 
      jsonobject = JSONfunctions 
        .getJSONfromURL("YOUR_PATH_URL_CONECT.PHP"); 

      try { 



       // Locate the array name in JSON 
       jsonarray = jsonobject.getJSONArray("value"); 


       for (int i = 0; i < jsonarray.length(); i++) { 
        HashMap<String, String> map = new HashMap<String, String>(); 
        jsonobject = jsonarray.getJSONObject(i); 
        // Retrive JSON Objects 
        map.put("thumbImage", jsonobject.getString("thumbImage")); 
        map.put("title", jsonobject.getString("title")); 


        // Set the JSON Objects into the array 
        arraylist.add(map); 
       } 
      } catch (JSONException e) { 
       Log.e("Error", e.getMessage()); 
       e.printStackTrace(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void args) { 
      // Locate the listview in listview_main.xml 
      listview = (ListView) findViewById(R.id.listview); 
      // Pass the results into ListViewAdapter.java 
      adapter = new ListViewAdapter(MainActivity.this, arraylist); 
      // Set the adapter to the ListView 
      listview.setAdapter(adapter); 
      // Close the progressdialog 
      mProgressDialog.dismiss(); 


       return; 

     } 
    } 

YOUR_PATH_URL_CONECT.PHP

echo '{"value":'.json_encode($yourArrayJsonObject).'}'; 

现在做创建适配器的其余部分。