Android Studio RssFeed

时间:2016-03-14 05:46:53

标签: android

我正在用android工作室写一个rssfeed我正在使用模拟器。我的代码编译并启动但它没有在屏幕上显示任何内容,除了顶部的标题MyRssFeed。有什么我想念的吗?

类别:

 APICommunicator *api = [[APICommunicator alloc] init];
             _searchTermArray=[[NSMutableArray alloc]init];
            NSDictionary *arr = [api getGoogleAPIArrByPOST:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&region=BD@&types=geocode&key=%@",searchTerms,API_KEY]  parameter:nil];
            NSString *areaName;
            for (areaName in arr) {
                _searchTermArray=[[arr valueForKey:@"predictions"]valueForKey:@"description"];



            }

          //  _searchTermArray=[[NSMutableArray alloc]initWithArray:arr];
            NSLog(@"%@",[_searchTermArray description]);

XML文件

package jrodriguez.myrssfeed;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
* Created by Jennifer Rodriguez on 3/8/2016.
*/
public class MainActivity extends AppCompatActivity {
private TextView src;


protected void OnCreate(Bundle SavedInstanceState) {
    super.onCreate(SavedInstanceState);
    setContentView(R.layout.activity_main);
    src = (TextView) findViewById(R.id.text);
}

public void fetch(View v) {
    Downloader d = new Downloader();
    d.execute("https://en.wikipedia.org/wiki/Main_Page");
    try {
        src.setText(d.get());

    } catch (Exception e) {
        Log.e("Error to thread", e.toString());
    }
}

class Downloader extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        String result = null;
        try {
            URL url = new URL(urls[0]);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            InputStream in = conn.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line = null;
            while ((line = reader.readLine()) != null) {
                result = result + line;
            }
            conn.disconnect();
            reader.close();
        } catch (Exception e) {
            Log.e("error to fetching", e.toString());
        }
        return result;
    }


}

清单

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res
 /android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/text"
    android:enabled="true" />

    <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Fetch"
    android:id="@+id/Fetch"
    android:enabled="true"
    android:clickable="true" />
   </LinearLayout>

1 个答案:

答案 0 :(得分:1)

您需要进行以下更改。

Button btn;

protected void OnCreate(Bundle SavedInstanceState) {
    super.onCreate(SavedInstanceState);
    setContentView(R.layout.activity_main);
    src = (TextView) findViewById(R.id.text);
    btn = (Button) findViewById(R.id.Fetch);
    btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                       fetch();
            }
        });
}

public void fetch() {
 //
}