Listview not showinng the data but showinng the blank position where the value is to be shown
I am parsing a JSON
and inflating the listview
with it. First listview is showing the correct value but when i am opening another activity from my contributors button, second listview
is not showing any value but displays a blank space where the text is to be displayed.
Here is my code...
Main Activity
package com.example.pc.jbossoutreachapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public void getStarted(View view)
Intent intent = new Intent(this, repositories.class);
startActivity(intent);
layout activity.main
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="358dp"
android:layout_height="251dp"
android:contentDescription="@string/ContentDescipt"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="31dp"
android:layout_marginBottom="1dp"
android:gravity="center"
android:text="@string/JBoss"
android:textColor="@android:color/holo_red_dark"
android:textSize="@dimen/size"
android:textStyle="bold"
app:fontFamily="sans-serif-smallcaps"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="25dp"
android:gravity="center"
android:text="@string/JBoss_intro"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/button"
android:layout_width="114dp"
android:layout_height="48dp"
android:background="#f0e68c"
android:onClick="getStarted"
android:text="@string/Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
</android.support.constraint.ConstraintLayout>
repositories class
Here the code works fine and the items are shown in the listview
HttpHandler class makes service call and returns Json String.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class repositories extends AppCompatActivity
private String TAG = MainActivity.class.getSimpleName();
private ProgressDialog ProgDialog;
private ListView listview;
private static String url = "https://api.github.com/orgs/JBossOutreach/repos";
ArrayList<HashMap<String,String>> RepoDetails;
public void link(View view)
TextView text = findViewById(R.id.Repolink);
String url = text.getText().toString();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
public void Contributors(View view)
listview = findViewById(R.id.list);
TextView name = findViewById(R.id.RepositoryName);
String n = name.getText().toString();
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Intent intent = new Intent(this, contributors.class);
Bundle bundle = new Bundle();
bundle.putString("url", url1);
intent.putExtras(bundle);
startActivity(intent);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.repositories);
RepoDetails = new ArrayList<>();
listview = (ListView)findViewById(R.id.list);
new GetContacts().execute();
private class GetContacts extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
ProgDialog = new ProgressDialog(repositories.this);
ProgDialog.setMessage("Please wait...");
ProgDialog.setCancelable(false);
ProgDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler sh = new HttpHandler();
String Json_String = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_String);
if(Json_String != null)
try
JSONArray array = new JSONArray(Json_String);
for(int i = 0; i < array.length(); i++)
JSONObject ob = array.getJSONObject(i);
String name = ob.getString("name");
JSONObject owner = ob.getJSONObject("owner");
String link = owner.getString("html_url");
HashMap<String, String> contact = new HashMap<>();
contact.put("name", name);
contact.put("link", link+"/"+name);
RepoDetails.add(contact);
catch(final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
else
Log.e(TAG, "Couldn't get Json from server");
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Couldn't get json from server ", Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if(ProgDialog.isShowing())
ProgDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
repositories.this, RepoDetails, R.layout.repo_list_item, new String
"name", "link", new intR.id.RepositoryName, R.id.Repolink);
listview.setAdapter(adapter);
repositories.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading1"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
repo_list_itmen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/RepositoryName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/NameRepo" />
<TextView
android:id="@+id/Repolink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="link"
android:paddingBottom="8dp"
android:textColor="@color/colorAccent" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="Contributors"
android:text="@string/Contributors" />
</LinearLayout>
contributors class
Problem starts from here no items are displayed but only the blank space for the items are displayed.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class contributors extends AppCompatActivity
private String TAG = contributors.class.getSimpleName();
ArrayList<HashMap<String, String>> names;
ListView lv;
private ProgressDialog progressDialog;
static String url;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contributors);
names = new ArrayList<>();
lv = findViewById(R.id.list2);
Bundle bundle = getIntent().getExtras();
System.out.print(url);
url = bundle.getString("url");
new contributors.getcontrib().execute();
private class getcontrib extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
progressDialog = new ProgressDialog(contributors.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler hd = new HttpHandler();
String Json_result = hd.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_result);
if (Json_result != null)
try
JSONArray array = new JSONArray(Json_result);
for (int i = 0; i < array.length(); i++)
JSONObject obj = array.getJSONObject(i);
String contributor_name = obj.getString("login");
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("name", contributor_name);
names.add(hashMap);
catch (final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if (progressDialog.isShowing())
progressDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
((SimpleAdapter) adapter).notifyDataSetChanged();
lv.setAdapter(adapter);
contributors.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading2"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
contributors_list_items.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/ContributorsName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/colorPrimaryDark" />
</LinearLayout>
java android xml listview
|
show 3 more comments
I am parsing a JSON
and inflating the listview
with it. First listview is showing the correct value but when i am opening another activity from my contributors button, second listview
is not showing any value but displays a blank space where the text is to be displayed.
Here is my code...
Main Activity
package com.example.pc.jbossoutreachapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public void getStarted(View view)
Intent intent = new Intent(this, repositories.class);
startActivity(intent);
layout activity.main
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="358dp"
android:layout_height="251dp"
android:contentDescription="@string/ContentDescipt"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="31dp"
android:layout_marginBottom="1dp"
android:gravity="center"
android:text="@string/JBoss"
android:textColor="@android:color/holo_red_dark"
android:textSize="@dimen/size"
android:textStyle="bold"
app:fontFamily="sans-serif-smallcaps"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="25dp"
android:gravity="center"
android:text="@string/JBoss_intro"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/button"
android:layout_width="114dp"
android:layout_height="48dp"
android:background="#f0e68c"
android:onClick="getStarted"
android:text="@string/Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
</android.support.constraint.ConstraintLayout>
repositories class
Here the code works fine and the items are shown in the listview
HttpHandler class makes service call and returns Json String.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class repositories extends AppCompatActivity
private String TAG = MainActivity.class.getSimpleName();
private ProgressDialog ProgDialog;
private ListView listview;
private static String url = "https://api.github.com/orgs/JBossOutreach/repos";
ArrayList<HashMap<String,String>> RepoDetails;
public void link(View view)
TextView text = findViewById(R.id.Repolink);
String url = text.getText().toString();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
public void Contributors(View view)
listview = findViewById(R.id.list);
TextView name = findViewById(R.id.RepositoryName);
String n = name.getText().toString();
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Intent intent = new Intent(this, contributors.class);
Bundle bundle = new Bundle();
bundle.putString("url", url1);
intent.putExtras(bundle);
startActivity(intent);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.repositories);
RepoDetails = new ArrayList<>();
listview = (ListView)findViewById(R.id.list);
new GetContacts().execute();
private class GetContacts extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
ProgDialog = new ProgressDialog(repositories.this);
ProgDialog.setMessage("Please wait...");
ProgDialog.setCancelable(false);
ProgDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler sh = new HttpHandler();
String Json_String = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_String);
if(Json_String != null)
try
JSONArray array = new JSONArray(Json_String);
for(int i = 0; i < array.length(); i++)
JSONObject ob = array.getJSONObject(i);
String name = ob.getString("name");
JSONObject owner = ob.getJSONObject("owner");
String link = owner.getString("html_url");
HashMap<String, String> contact = new HashMap<>();
contact.put("name", name);
contact.put("link", link+"/"+name);
RepoDetails.add(contact);
catch(final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
else
Log.e(TAG, "Couldn't get Json from server");
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Couldn't get json from server ", Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if(ProgDialog.isShowing())
ProgDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
repositories.this, RepoDetails, R.layout.repo_list_item, new String
"name", "link", new intR.id.RepositoryName, R.id.Repolink);
listview.setAdapter(adapter);
repositories.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading1"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
repo_list_itmen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/RepositoryName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/NameRepo" />
<TextView
android:id="@+id/Repolink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="link"
android:paddingBottom="8dp"
android:textColor="@color/colorAccent" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="Contributors"
android:text="@string/Contributors" />
</LinearLayout>
contributors class
Problem starts from here no items are displayed but only the blank space for the items are displayed.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class contributors extends AppCompatActivity
private String TAG = contributors.class.getSimpleName();
ArrayList<HashMap<String, String>> names;
ListView lv;
private ProgressDialog progressDialog;
static String url;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contributors);
names = new ArrayList<>();
lv = findViewById(R.id.list2);
Bundle bundle = getIntent().getExtras();
System.out.print(url);
url = bundle.getString("url");
new contributors.getcontrib().execute();
private class getcontrib extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
progressDialog = new ProgressDialog(contributors.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler hd = new HttpHandler();
String Json_result = hd.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_result);
if (Json_result != null)
try
JSONArray array = new JSONArray(Json_result);
for (int i = 0; i < array.length(); i++)
JSONObject obj = array.getJSONObject(i);
String contributor_name = obj.getString("login");
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("name", contributor_name);
names.add(hashMap);
catch (final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if (progressDialog.isShowing())
progressDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
((SimpleAdapter) adapter).notifyDataSetChanged();
lv.setAdapter(adapter);
contributors.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading2"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
contributors_list_items.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/ContributorsName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/colorPrimaryDark" />
</LinearLayout>
java android xml listview
Seems you are new to the android development world. First step I would suggest you to check whether you are getting API response or not.
– Paresh Mayani
Nov 13 '18 at 5:31
1
yup, I have just started. How to check that?
– D buiss
Nov 13 '18 at 5:32
hashMap.put("name", contributor_name);
this will write all values to single entry in hashmap as hashmap doesnt allow same key for different values.
– Karan Mer
Nov 13 '18 at 5:33
@Dbuiss put breakpoints and debug it. Or the best just check thelogcat
window, you will be finding logs as you are already printingLog.e(TAG, "Response from url: " + Json_result);
– Paresh Mayani
Nov 13 '18 at 5:37
@KaranMer But this worked fine for first listview
– D buiss
Nov 13 '18 at 5:38
|
show 3 more comments
I am parsing a JSON
and inflating the listview
with it. First listview is showing the correct value but when i am opening another activity from my contributors button, second listview
is not showing any value but displays a blank space where the text is to be displayed.
Here is my code...
Main Activity
package com.example.pc.jbossoutreachapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public void getStarted(View view)
Intent intent = new Intent(this, repositories.class);
startActivity(intent);
layout activity.main
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="358dp"
android:layout_height="251dp"
android:contentDescription="@string/ContentDescipt"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="31dp"
android:layout_marginBottom="1dp"
android:gravity="center"
android:text="@string/JBoss"
android:textColor="@android:color/holo_red_dark"
android:textSize="@dimen/size"
android:textStyle="bold"
app:fontFamily="sans-serif-smallcaps"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="25dp"
android:gravity="center"
android:text="@string/JBoss_intro"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/button"
android:layout_width="114dp"
android:layout_height="48dp"
android:background="#f0e68c"
android:onClick="getStarted"
android:text="@string/Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
</android.support.constraint.ConstraintLayout>
repositories class
Here the code works fine and the items are shown in the listview
HttpHandler class makes service call and returns Json String.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class repositories extends AppCompatActivity
private String TAG = MainActivity.class.getSimpleName();
private ProgressDialog ProgDialog;
private ListView listview;
private static String url = "https://api.github.com/orgs/JBossOutreach/repos";
ArrayList<HashMap<String,String>> RepoDetails;
public void link(View view)
TextView text = findViewById(R.id.Repolink);
String url = text.getText().toString();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
public void Contributors(View view)
listview = findViewById(R.id.list);
TextView name = findViewById(R.id.RepositoryName);
String n = name.getText().toString();
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Intent intent = new Intent(this, contributors.class);
Bundle bundle = new Bundle();
bundle.putString("url", url1);
intent.putExtras(bundle);
startActivity(intent);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.repositories);
RepoDetails = new ArrayList<>();
listview = (ListView)findViewById(R.id.list);
new GetContacts().execute();
private class GetContacts extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
ProgDialog = new ProgressDialog(repositories.this);
ProgDialog.setMessage("Please wait...");
ProgDialog.setCancelable(false);
ProgDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler sh = new HttpHandler();
String Json_String = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_String);
if(Json_String != null)
try
JSONArray array = new JSONArray(Json_String);
for(int i = 0; i < array.length(); i++)
JSONObject ob = array.getJSONObject(i);
String name = ob.getString("name");
JSONObject owner = ob.getJSONObject("owner");
String link = owner.getString("html_url");
HashMap<String, String> contact = new HashMap<>();
contact.put("name", name);
contact.put("link", link+"/"+name);
RepoDetails.add(contact);
catch(final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
else
Log.e(TAG, "Couldn't get Json from server");
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Couldn't get json from server ", Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if(ProgDialog.isShowing())
ProgDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
repositories.this, RepoDetails, R.layout.repo_list_item, new String
"name", "link", new intR.id.RepositoryName, R.id.Repolink);
listview.setAdapter(adapter);
repositories.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading1"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
repo_list_itmen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/RepositoryName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/NameRepo" />
<TextView
android:id="@+id/Repolink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="link"
android:paddingBottom="8dp"
android:textColor="@color/colorAccent" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="Contributors"
android:text="@string/Contributors" />
</LinearLayout>
contributors class
Problem starts from here no items are displayed but only the blank space for the items are displayed.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class contributors extends AppCompatActivity
private String TAG = contributors.class.getSimpleName();
ArrayList<HashMap<String, String>> names;
ListView lv;
private ProgressDialog progressDialog;
static String url;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contributors);
names = new ArrayList<>();
lv = findViewById(R.id.list2);
Bundle bundle = getIntent().getExtras();
System.out.print(url);
url = bundle.getString("url");
new contributors.getcontrib().execute();
private class getcontrib extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
progressDialog = new ProgressDialog(contributors.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler hd = new HttpHandler();
String Json_result = hd.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_result);
if (Json_result != null)
try
JSONArray array = new JSONArray(Json_result);
for (int i = 0; i < array.length(); i++)
JSONObject obj = array.getJSONObject(i);
String contributor_name = obj.getString("login");
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("name", contributor_name);
names.add(hashMap);
catch (final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if (progressDialog.isShowing())
progressDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
((SimpleAdapter) adapter).notifyDataSetChanged();
lv.setAdapter(adapter);
contributors.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading2"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
contributors_list_items.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/ContributorsName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/colorPrimaryDark" />
</LinearLayout>
java android xml listview
I am parsing a JSON
and inflating the listview
with it. First listview is showing the correct value but when i am opening another activity from my contributors button, second listview
is not showing any value but displays a blank space where the text is to be displayed.
Here is my code...
Main Activity
package com.example.pc.jbossoutreachapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public void getStarted(View view)
Intent intent = new Intent(this, repositories.class);
startActivity(intent);
layout activity.main
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="358dp"
android:layout_height="251dp"
android:contentDescription="@string/ContentDescipt"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="31dp"
android:layout_marginBottom="1dp"
android:gravity="center"
android:text="@string/JBoss"
android:textColor="@android:color/holo_red_dark"
android:textSize="@dimen/size"
android:textStyle="bold"
app:fontFamily="sans-serif-smallcaps"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="25dp"
android:gravity="center"
android:text="@string/JBoss_intro"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/button"
android:layout_width="114dp"
android:layout_height="48dp"
android:background="#f0e68c"
android:onClick="getStarted"
android:text="@string/Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
</android.support.constraint.ConstraintLayout>
repositories class
Here the code works fine and the items are shown in the listview
HttpHandler class makes service call and returns Json String.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class repositories extends AppCompatActivity
private String TAG = MainActivity.class.getSimpleName();
private ProgressDialog ProgDialog;
private ListView listview;
private static String url = "https://api.github.com/orgs/JBossOutreach/repos";
ArrayList<HashMap<String,String>> RepoDetails;
public void link(View view)
TextView text = findViewById(R.id.Repolink);
String url = text.getText().toString();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
public void Contributors(View view)
listview = findViewById(R.id.list);
TextView name = findViewById(R.id.RepositoryName);
String n = name.getText().toString();
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Intent intent = new Intent(this, contributors.class);
Bundle bundle = new Bundle();
bundle.putString("url", url1);
intent.putExtras(bundle);
startActivity(intent);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.repositories);
RepoDetails = new ArrayList<>();
listview = (ListView)findViewById(R.id.list);
new GetContacts().execute();
private class GetContacts extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
ProgDialog = new ProgressDialog(repositories.this);
ProgDialog.setMessage("Please wait...");
ProgDialog.setCancelable(false);
ProgDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler sh = new HttpHandler();
String Json_String = sh.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_String);
if(Json_String != null)
try
JSONArray array = new JSONArray(Json_String);
for(int i = 0; i < array.length(); i++)
JSONObject ob = array.getJSONObject(i);
String name = ob.getString("name");
JSONObject owner = ob.getJSONObject("owner");
String link = owner.getString("html_url");
HashMap<String, String> contact = new HashMap<>();
contact.put("name", name);
contact.put("link", link+"/"+name);
RepoDetails.add(contact);
catch(final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
else
Log.e(TAG, "Couldn't get Json from server");
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Couldn't get json from server ", Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if(ProgDialog.isShowing())
ProgDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
repositories.this, RepoDetails, R.layout.repo_list_item, new String
"name", "link", new intR.id.RepositoryName, R.id.Repolink);
listview.setAdapter(adapter);
repositories.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading1"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
repo_list_itmen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/RepositoryName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/NameRepo" />
<TextView
android:id="@+id/Repolink"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="link"
android:paddingBottom="8dp"
android:textColor="@color/colorAccent" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="Contributors"
android:text="@string/Contributors" />
</LinearLayout>
contributors class
Problem starts from here no items are displayed but only the blank space for the items are displayed.
package com.example.pc.jbossoutreachapp;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class contributors extends AppCompatActivity
private String TAG = contributors.class.getSimpleName();
ArrayList<HashMap<String, String>> names;
ListView lv;
private ProgressDialog progressDialog;
static String url;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.contributors);
names = new ArrayList<>();
lv = findViewById(R.id.list2);
Bundle bundle = getIntent().getExtras();
System.out.print(url);
url = bundle.getString("url");
new contributors.getcontrib().execute();
private class getcontrib extends AsyncTask<Void, Void, Void>
@Override
protected void onPreExecute()
super.onPreExecute();
progressDialog = new ProgressDialog(contributors.this);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.show();
@Override
protected Void doInBackground(Void... voids)
HttpHandler hd = new HttpHandler();
String Json_result = hd.makeServiceCall(url);
Log.e(TAG, "Response from url: " + Json_result);
if (Json_result != null)
try
JSONArray array = new JSONArray(Json_result);
for (int i = 0; i < array.length(); i++)
JSONObject obj = array.getJSONObject(i);
String contributor_name = obj.getString("login");
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("name", contributor_name);
names.add(hashMap);
catch (final JSONException e)
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable()
@Override
public void run()
Toast.makeText(getApplicationContext(),
"Json Parsing error: " + e.getMessage(), Toast.LENGTH_LONG).show();
);
return null;
@Override
protected void onPostExecute(Void aVoid)
super.onPostExecute(aVoid);
if (progressDialog.isShowing())
progressDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
((SimpleAdapter) adapter).notifyDataSetChanged();
lv.setAdapter(adapter);
contributors.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="109dp"
android:layout_marginLeft="109dp"
android:layout_marginTop="0dp"
android:text="@string/Heading2"
android:textSize="24sp"
android:textStyle="bold" />
<ListView
android:id="@+id/list2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
</RelativeLayout>
contributors_list_items.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/ContributorsName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="8dp"
android:textColor="@color/colorPrimaryDark" />
</LinearLayout>
java android xml listview
java android xml listview
edited Nov 13 '18 at 6:42
Ali Ahmed
1,3611314
1,3611314
asked Nov 13 '18 at 5:21
D buissD buiss
257
257
Seems you are new to the android development world. First step I would suggest you to check whether you are getting API response or not.
– Paresh Mayani
Nov 13 '18 at 5:31
1
yup, I have just started. How to check that?
– D buiss
Nov 13 '18 at 5:32
hashMap.put("name", contributor_name);
this will write all values to single entry in hashmap as hashmap doesnt allow same key for different values.
– Karan Mer
Nov 13 '18 at 5:33
@Dbuiss put breakpoints and debug it. Or the best just check thelogcat
window, you will be finding logs as you are already printingLog.e(TAG, "Response from url: " + Json_result);
– Paresh Mayani
Nov 13 '18 at 5:37
@KaranMer But this worked fine for first listview
– D buiss
Nov 13 '18 at 5:38
|
show 3 more comments
Seems you are new to the android development world. First step I would suggest you to check whether you are getting API response or not.
– Paresh Mayani
Nov 13 '18 at 5:31
1
yup, I have just started. How to check that?
– D buiss
Nov 13 '18 at 5:32
hashMap.put("name", contributor_name);
this will write all values to single entry in hashmap as hashmap doesnt allow same key for different values.
– Karan Mer
Nov 13 '18 at 5:33
@Dbuiss put breakpoints and debug it. Or the best just check thelogcat
window, you will be finding logs as you are already printingLog.e(TAG, "Response from url: " + Json_result);
– Paresh Mayani
Nov 13 '18 at 5:37
@KaranMer But this worked fine for first listview
– D buiss
Nov 13 '18 at 5:38
Seems you are new to the android development world. First step I would suggest you to check whether you are getting API response or not.
– Paresh Mayani
Nov 13 '18 at 5:31
Seems you are new to the android development world. First step I would suggest you to check whether you are getting API response or not.
– Paresh Mayani
Nov 13 '18 at 5:31
1
1
yup, I have just started. How to check that?
– D buiss
Nov 13 '18 at 5:32
yup, I have just started. How to check that?
– D buiss
Nov 13 '18 at 5:32
hashMap.put("name", contributor_name);
this will write all values to single entry in hashmap as hashmap doesnt allow same key for different values.– Karan Mer
Nov 13 '18 at 5:33
hashMap.put("name", contributor_name);
this will write all values to single entry in hashmap as hashmap doesnt allow same key for different values.– Karan Mer
Nov 13 '18 at 5:33
@Dbuiss put breakpoints and debug it. Or the best just check the
logcat
window, you will be finding logs as you are already printing Log.e(TAG, "Response from url: " + Json_result);
– Paresh Mayani
Nov 13 '18 at 5:37
@Dbuiss put breakpoints and debug it. Or the best just check the
logcat
window, you will be finding logs as you are already printing Log.e(TAG, "Response from url: " + Json_result);
– Paresh Mayani
Nov 13 '18 at 5:37
@KaranMer But this worked fine for first listview
– D buiss
Nov 13 '18 at 5:38
@KaranMer But this worked fine for first listview
– D buiss
Nov 13 '18 at 5:38
|
show 3 more comments
2 Answers
2
active
oldest
votes
Change your AsyncTask call from
new contributors.getcontrib().execute();
to
new getcontrib().execute();
Edit:
Also, change your adapter initialization code from:
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
to
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"name", new intR.id.ContributorsName);
Note: you have added your contributers name in "name" key and not in "contributors" key
nothing happened.
– D buiss
Nov 13 '18 at 5:34
@Dbuiss also, update your adapter code, like above.
– Firoz Memon
Nov 13 '18 at 6:06
hey u copy my method Nice
– suresh madaparthi
Nov 13 '18 at 6:56
ListAdapter adapter = new SimpleAdapter( contributors.this, names, R.layout.contributor_list_items, new String "name", new intR.id.ContributorsName);
– suresh madaparthi
Nov 13 '18 at 6:56
new intR.id.ContributorsName); add same name "name", new intR.id.ContributorsName)
– suresh madaparthi
Nov 13 '18 at 6:57
add a comment |
Check Ur Response First .
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Ur Json Respo
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#list-contributors"
n is the String variable for storing the name.
– D buiss
Nov 13 '18 at 5:43
I am getting the response in the logcat.
– D buiss
Nov 13 '18 at 5:44
how check ur message
– suresh madaparthi
Nov 13 '18 at 5:45
"message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:45
how ur response "message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:46
|
show 6 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274301%2flistview-not-showinng-the-data-but-showinng-the-blank-position-where-the-value-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change your AsyncTask call from
new contributors.getcontrib().execute();
to
new getcontrib().execute();
Edit:
Also, change your adapter initialization code from:
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
to
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"name", new intR.id.ContributorsName);
Note: you have added your contributers name in "name" key and not in "contributors" key
nothing happened.
– D buiss
Nov 13 '18 at 5:34
@Dbuiss also, update your adapter code, like above.
– Firoz Memon
Nov 13 '18 at 6:06
hey u copy my method Nice
– suresh madaparthi
Nov 13 '18 at 6:56
ListAdapter adapter = new SimpleAdapter( contributors.this, names, R.layout.contributor_list_items, new String "name", new intR.id.ContributorsName);
– suresh madaparthi
Nov 13 '18 at 6:56
new intR.id.ContributorsName); add same name "name", new intR.id.ContributorsName)
– suresh madaparthi
Nov 13 '18 at 6:57
add a comment |
Change your AsyncTask call from
new contributors.getcontrib().execute();
to
new getcontrib().execute();
Edit:
Also, change your adapter initialization code from:
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
to
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"name", new intR.id.ContributorsName);
Note: you have added your contributers name in "name" key and not in "contributors" key
nothing happened.
– D buiss
Nov 13 '18 at 5:34
@Dbuiss also, update your adapter code, like above.
– Firoz Memon
Nov 13 '18 at 6:06
hey u copy my method Nice
– suresh madaparthi
Nov 13 '18 at 6:56
ListAdapter adapter = new SimpleAdapter( contributors.this, names, R.layout.contributor_list_items, new String "name", new intR.id.ContributorsName);
– suresh madaparthi
Nov 13 '18 at 6:56
new intR.id.ContributorsName); add same name "name", new intR.id.ContributorsName)
– suresh madaparthi
Nov 13 '18 at 6:57
add a comment |
Change your AsyncTask call from
new contributors.getcontrib().execute();
to
new getcontrib().execute();
Edit:
Also, change your adapter initialization code from:
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
to
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"name", new intR.id.ContributorsName);
Note: you have added your contributers name in "name" key and not in "contributors" key
Change your AsyncTask call from
new contributors.getcontrib().execute();
to
new getcontrib().execute();
Edit:
Also, change your adapter initialization code from:
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"contributors", new intR.id.ContributorsName);
to
ListAdapter adapter = new SimpleAdapter(
contributors.this, names, R.layout.contributor_list_items, new String
"name", new intR.id.ContributorsName);
Note: you have added your contributers name in "name" key and not in "contributors" key
edited Nov 13 '18 at 6:05
answered Nov 13 '18 at 5:32
Firoz MemonFiroz Memon
1,79721122
1,79721122
nothing happened.
– D buiss
Nov 13 '18 at 5:34
@Dbuiss also, update your adapter code, like above.
– Firoz Memon
Nov 13 '18 at 6:06
hey u copy my method Nice
– suresh madaparthi
Nov 13 '18 at 6:56
ListAdapter adapter = new SimpleAdapter( contributors.this, names, R.layout.contributor_list_items, new String "name", new intR.id.ContributorsName);
– suresh madaparthi
Nov 13 '18 at 6:56
new intR.id.ContributorsName); add same name "name", new intR.id.ContributorsName)
– suresh madaparthi
Nov 13 '18 at 6:57
add a comment |
nothing happened.
– D buiss
Nov 13 '18 at 5:34
@Dbuiss also, update your adapter code, like above.
– Firoz Memon
Nov 13 '18 at 6:06
hey u copy my method Nice
– suresh madaparthi
Nov 13 '18 at 6:56
ListAdapter adapter = new SimpleAdapter( contributors.this, names, R.layout.contributor_list_items, new String "name", new intR.id.ContributorsName);
– suresh madaparthi
Nov 13 '18 at 6:56
new intR.id.ContributorsName); add same name "name", new intR.id.ContributorsName)
– suresh madaparthi
Nov 13 '18 at 6:57
nothing happened.
– D buiss
Nov 13 '18 at 5:34
nothing happened.
– D buiss
Nov 13 '18 at 5:34
@Dbuiss also, update your adapter code, like above.
– Firoz Memon
Nov 13 '18 at 6:06
@Dbuiss also, update your adapter code, like above.
– Firoz Memon
Nov 13 '18 at 6:06
hey u copy my method Nice
– suresh madaparthi
Nov 13 '18 at 6:56
hey u copy my method Nice
– suresh madaparthi
Nov 13 '18 at 6:56
ListAdapter adapter = new SimpleAdapter( contributors.this, names, R.layout.contributor_list_items, new String "name", new intR.id.ContributorsName);
– suresh madaparthi
Nov 13 '18 at 6:56
ListAdapter adapter = new SimpleAdapter( contributors.this, names, R.layout.contributor_list_items, new String "name", new intR.id.ContributorsName);
– suresh madaparthi
Nov 13 '18 at 6:56
new intR.id.ContributorsName); add same name "name", new intR.id.ContributorsName)
– suresh madaparthi
Nov 13 '18 at 6:57
new intR.id.ContributorsName); add same name "name", new intR.id.ContributorsName)
– suresh madaparthi
Nov 13 '18 at 6:57
add a comment |
Check Ur Response First .
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Ur Json Respo
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#list-contributors"
n is the String variable for storing the name.
– D buiss
Nov 13 '18 at 5:43
I am getting the response in the logcat.
– D buiss
Nov 13 '18 at 5:44
how check ur message
– suresh madaparthi
Nov 13 '18 at 5:45
"message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:45
how ur response "message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:46
|
show 6 more comments
Check Ur Response First .
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Ur Json Respo
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#list-contributors"
n is the String variable for storing the name.
– D buiss
Nov 13 '18 at 5:43
I am getting the response in the logcat.
– D buiss
Nov 13 '18 at 5:44
how check ur message
– suresh madaparthi
Nov 13 '18 at 5:45
"message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:45
how ur response "message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:46
|
show 6 more comments
Check Ur Response First .
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Ur Json Respo
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#list-contributors"
Check Ur Response First .
String url1 = "https://api.github.com/repos/JBossOutreach/"+n+"/contributors";
Ur Json Respo
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#list-contributors"
answered Nov 13 '18 at 5:42
suresh madaparthisuresh madaparthi
251110
251110
n is the String variable for storing the name.
– D buiss
Nov 13 '18 at 5:43
I am getting the response in the logcat.
– D buiss
Nov 13 '18 at 5:44
how check ur message
– suresh madaparthi
Nov 13 '18 at 5:45
"message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:45
how ur response "message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:46
|
show 6 more comments
n is the String variable for storing the name.
– D buiss
Nov 13 '18 at 5:43
I am getting the response in the logcat.
– D buiss
Nov 13 '18 at 5:44
how check ur message
– suresh madaparthi
Nov 13 '18 at 5:45
"message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:45
how ur response "message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:46
n is the String variable for storing the name.
– D buiss
Nov 13 '18 at 5:43
n is the String variable for storing the name.
– D buiss
Nov 13 '18 at 5:43
I am getting the response in the logcat.
– D buiss
Nov 13 '18 at 5:44
I am getting the response in the logcat.
– D buiss
Nov 13 '18 at 5:44
how check ur message
– suresh madaparthi
Nov 13 '18 at 5:45
how check ur message
– suresh madaparthi
Nov 13 '18 at 5:45
"message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:45
"message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:45
how ur response "message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:46
how ur response "message": "Not Found",
– suresh madaparthi
Nov 13 '18 at 5:46
|
show 6 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274301%2flistview-not-showinng-the-data-but-showinng-the-blank-position-where-the-value-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Seems you are new to the android development world. First step I would suggest you to check whether you are getting API response or not.
– Paresh Mayani
Nov 13 '18 at 5:31
1
yup, I have just started. How to check that?
– D buiss
Nov 13 '18 at 5:32
hashMap.put("name", contributor_name);
this will write all values to single entry in hashmap as hashmap doesnt allow same key for different values.– Karan Mer
Nov 13 '18 at 5:33
@Dbuiss put breakpoints and debug it. Or the best just check the
logcat
window, you will be finding logs as you are already printingLog.e(TAG, "Response from url: " + Json_result);
– Paresh Mayani
Nov 13 '18 at 5:37
@KaranMer But this worked fine for first listview
– D buiss
Nov 13 '18 at 5:38