package com.kaleidosstudio.listview_load_data_from_json;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.example.listview_load_data_from_json.R;
import com.kaleidosstudio.listview_load_data_from_json.Download_data.download_complete;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends Activity implements download_complete {
public ListView list;
public ArrayList<Articles> countries = new ArrayList<Articles>();
public ListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.list);
adapter = new ListAdapter(this);
list.setAdapter(adapter);
Download_data download_data = new Download_data((download_complete) this);
download_data.download_data_from_link("http://jsonplaceholder.typicode.com/posts");
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View itemClicked, int position,
long id) {
Intent intent = new Intent(MainActivity.this, Article.class);
startActivity(intent);
// TextView textView = (TextView) itemClicked.findViewById(R.id.name);
// String strText = textView.getText().toString(); // получаем текст нажатого элемента
//
// if(strText.equalsIgnoreCase(getResources().getString(R.string.app_name))) {
// // Запускаем активность, связанную с определенным именем кота
// startActivity(new Intent(MainActivity.this, Article.class));
// }
}
});}
public void get_data(String data)
{
try {
JSONArray data_array=new JSONArray(data);
for (int i = 0 ; i < data_array.length() ; i++)
{
JSONObject obj=new JSONObject(data_array.get(i).toString());
Articles add=new Articles();
add.title = obj.getString("title");
//add.code = obj.getString("id");
countries.add(add);
}
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.example.listview_load_data_from_json/com.kaleidosstudio.listview_load_data_from_json.Article}: java.lang.IllegalStateException:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
<activity android:name="com.kaleidosstudio.listview_load_data_from_json.Article"
android:theme ="@style/Theme.AppCompat">