This is my JSON:
{
"NEWS": [
{
"ID": 1,
"Title": "A",
"News": "A"
},
{
"ID": 2,
"Title": "B",
"News": "B"
}
]
}
I am parsing this JSON in a listview and just showing the Title. Now, If I click on listview item, say, I clicked "A", I want to populate Title and News in other activity. How can i constraint them?
ArrayList<HashMap<String, String>> newList ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_news);
newList = new ArrayList<>();
String items = String.valueOf(newList);
lv = (ListView) findViewById(R.id.list);
new GetContacts().execute();
}
private class GetContacts extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
HttpHandler sh = new HttpHandler();
String jsonStr = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray NEWS= jsonObj.getJSONArray("NEWS");
for (int i = 0; i < NEWS.length(); i++) {
JSONObject c = icerik.getJSONObject(i);
String ID= c.getString("ID");
String Title= c.getString("Title");
String News= c.getString("News");
HashMap<String, String> newss= new HashMap<>();
newss.put("ID", ID);
newss.put("Title", Title);
newss.put("News", News);
newList.add(newss);
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
final ListAdapter adapter = new SimpleAdapter(
news.this, newList,
R.layout.new_list, new String[]{"Title"},
new int[]{
R.id.Ttile});
lv.setAdapter(adapter);
lv.setClickable(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position >= 0)
{
//Intent myIntent = new Intent(view.getContext(), MYSECONDACTIVTY.class);
//startActivityForResult(myIntent, 0);
}
I found it, and tried but it doesn't work. I just want to show item details on other activity when I click on list item.