Android ListView won't populate - android

I'm trying to populate my ListView with values from a string array. There are values in the string array, as I've checked to make sure. I'm using code that, from what I've seen from previous searches, is correct. I'm running the app through an Android emulator and have tried creating a new emulator, cleaning the project, and restarting Eclipse. But still when the app starts up there is no data in the list.
I'm using the Galaxy Nexus emulator running Android 4.2.
MainActivity.java:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView redditView = (ListView) findViewById(R.id.redditView);
String[] redditList = readRedditFeed();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1, redditList);
redditView.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public String[] readRedditFeed()
{
return output;
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ListView
android:id="#+id/redditView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>

You are parsing data in main thread it may give ANR.
Use either Thread and handler or AsyncTask.
After getting parsed result from thread use handler to set adapter in your list
OR
use AsyncTask doInbackground() method to receiving and parsing data and onPostExecute()
set adapter in your list.

just use an asyncTask to do the background work without blocking the UI.
private LoadingStuffTask task;
private String [] redditList;
private ArrayAdapter<String> adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView redditView = (ListView) findViewById(R.id.redditView);
task = new LoadingStuffTask();
task.execute("Process started!");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private class LoadingStuffTask extends
AsyncTask<String, String, String> {
#Override
protected String doInBackground(String... params) {
redditList=readRedditFeed()
}
#Override
protected void onProgressUpdate(
String... values) {
}
#Override
protected void onPostExecute(String result) {
pdia.dismiss();
adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1, redditList);
redditView.setAdapter(adapter);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
pdia = new ProgressDialog(classificaA.this);
pdia.setMessage("Doing background..");
pdia.show();
}
}
public String[] readRedditFeed()
{
ArrayList<String> redditList = new ArrayList<String>();
try
{
URL url = new URL("http://www.reddit.com/.json");
InputStream in = url.openStream();
DataInputStream din = new DataInputStream(new BufferedInputStream(in));
String line = "";
String lines = "";
while((line = din.readLine()) != null)
lines += line;
JSONObject json = (JSONObject) new JSONTokener(lines).nextValue();
json = (JSONObject) json.getJSONObject("data");
JSONArray jsonArr = (JSONArray) json.getJSONArray("children");
for(int i = 0; i < 5; i++)
{
json = jsonArr.getJSONObject(i);
json = (JSONObject) json.getJSONObject("data");
redditList.add(json.get("title").toString().replaceAll("\"", ""));
}
}
catch (Exception e)
{}
String[] output = new String[redditList.size()];
redditList.toArray(output);
return output;
}
}

Related

Asynctask onPostExecutive method assigning a value to instance variable but it is not showing that in mainActivity class.

I have a instance variable(art) of main activity class getting assigned with a value in onPostExecution method.Log statements prints the value of art in onPostExecute method.
But the value of art is null after the onPostExecute method.
public class MainActivity extends ActionBarActivity implements OnItemClickListener {
ListView listView1;
String[] dummyData = {"sunday","monday","tuesday","wednesday","thursday","friday","saturday","sunday","monday","tuesday",
"wednesday","thursday","friday","saturday","sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
ArrayAdapter<String> adapter ;
ArrayList<String> summery = new ArrayList<String>(4);
ArrayList<String> links = new ArrayList<String>(4);
Elements art;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String stringUrl = "https://techcards.wordpress.com";
Fetch fetch = new Fetch();
fetch.execute(stringUrl);
try{
for (int i =0;i<art.size() ;i++ ) {
Log.v("articles after post executive",art.get(i).toString());
links.add(i,art.get(i).getElementsByTag("a").toString());
Log.v("links",art.toString());
summery.add(i,art.get(i).getElementsByTag("p").text());
}
}catch(NullPointerException e){
e.printStackTrace();
System.out.println("art is null");
}
listView1 = (ListView) findViewById(R.id.listView1);
adapter = new ArrayAdapter<String>(this,R.layout.single_row,R.id.textView2, links);
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
TextView t = (TextView) view.findViewById(R.id.textView2);
String text =(String) t.getText();
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();//this makeText is a static method
}
// Fetch AsyncTask
private class Fetch extends AsyncTask<String, Void, Elements> {
#Override
protected Elements doInBackground(String... params) {
Elements articles = null;
try {
// Connect to the web site
Document doc = Jsoup.connect(params[0]).get();
Element main =doc.getElementById("content").getElementById("primary").
getElementById("main");
articles = main.getElementsByClass("entry-summary");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IO exception");
}
return articles;
}
protected void onPostExecute(Elements result) {
art = result;
for (int i =0;i<art.size() ;i++ ) {
Log.v("links in post executive",art.get(i).getElementsByTag("a").toString());
Log.v("summery in post executive",art.get(i).getElementsByTag("p").text());
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
art is giving null pointer exception when i'm trying to use it to update links and summery.
onPostExecute method run when doInBackground execution complete. so add data in adapter in onPostExecute instead of just after starting AsyncTask :
#Override
protected void onPostExecute(Elements result) {
super.onPostExecute(result);
// 1. Add data in summery from result
// 2. Pass summery to Adapter constructor
adapter = new ArrayAdapter<String>(MainActivity.this,R.layout.single_row,
R.id.textView2, links);
listView1.setAdapter(adapter);
}
AsyncTask works asynchronously. Those lines after:
fetch.execute(stringUrl);
doesn't work after onPostExecute but it works simultaneously (or so) with the code inside AsyncTask. That's why AsyncTask is called AsyncTask.
And that's why your art variable is null since onPostExecute doesn't get called yet.

do not load the data in android-pulltorefresh-and-loadmore library

I downloaded and imported the library [https://github.com/shontauro/android-pulltorefresh-and-loadmore][1]
Everything works fine. but when I try to change the code in my error output.
comment out what works. what appear below my not work. Even the logs are not shown. what am I doing wrong?
public class LoadMoreExampleActivity extends ListActivity {
// list with the data to show in the listview
private LinkedList<String> mListItems;
// The data to be displayed in the ListView
private String[] mNames = { "Fabian", "Carlos", "Alex", "Andrea", "Karla",
"Freddy", "Lazaro", "Hector", "Carolina", "Edwin", "Jhon",
"Edelmira", "Andres" };
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loadmore);
mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mNames));
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mListItems);
setListAdapter(adapter);
// set a listener to be invoked when the list reaches the end
((LoadMoreListView) getListView())
.setOnLoadMoreListener(new OnLoadMoreListener() {
public void onLoadMore() {
// Do the work to load more items at the end of list
// here
new LoadDataTask().execute();
}
});
}
private class LoadDataTask extends AsyncTask<String, Void, String> {
String[] mass;
#Override
protected String doInBackground(String... strings) {
Document doc;
if (isCancelled()) {
return null;
}
// Simulates a background task
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// }
// for (int i = 0; i < mNames.length; i++)
// mListItems.add("string"+i);
try {
doc = Jsoup.connect(link).get();
Elements eName = doc.select("name");
for (int i = 0; i < eName.size(); i++) {
mListItems.add(eName.get(i).ownText());
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String result) {
mListItems.add("Added after load more");
// We need notify the adapter that the data have been changed
((BaseAdapter) getListAdapter()).notifyDataSetChanged();
// Call onLoadMoreComplete when the LoadMore task, has finished
((LoadMoreListView) getListView()).onLoadMoreComplete();
super.onPostExecute(result);
}
#Override
protected void onCancelled() {
// Notify the loading more operation has finished
((LoadMoreListView) getListView()).onLoadMoreComplete();
}
}
}
And you do not forget to connect to the internet?
<uses-permission android:name="android.permission.INTERNET"/>

List view doesn't show text

I need to get text from a website which is done in a new thread. Then i need to put that text in a list view.
The problem is that i cant set up array adapter for list view until text is put in the lists used in that adapter. Lists are filled in that thread used for connecting to website.
I tried to solve that by setting up adapter in new thread run by first thread. Program starts without errors, but nothing shows up in list view.
I am using List view code from this site http://www.vogella.com/articles/AndroidListView/article.html
Im a newbie in java and android so i hope you understand what im trying to do :)
Heres the code
package com.example.studentservis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.R.string;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class MainActivity extends Activity {
String s;
List<String> headersList = new ArrayList<String>();
List<String> contentList = new ArrayList<String>();
ListView listview;
StableArrayAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.listView1);
threadStart();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void adapterInit()
{
adapter = new StableArrayAdapter(this, android.R.layout.simple_list_item_1, headersList);
listview.setAdapter(adapter);
}
private class StableArrayAdapter extends ArrayAdapter<String>{
HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
public StableArrayAdapter(Context context, int textViewResourceId,
List<String> objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
#Override
public long getItemId(int position) {
String item = getItem(position);
return mIdMap.get(item);
}
#Override
public boolean hasStableIds() {
return true;
}
}
public void threadStart()
{
//txtView.setText(stringHandler.getString());
new Thread(new Runnable() { // thread
public void run(){
try
{
webRequest();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Runnable()
{
#Override
public void run() {
// TODO Auto-generated method stub
adapterInit();
}
};
}
}).start();
}
public void webRequest() throws Exception{
String servisURL = "http://www.sczg.unizg.hr/student-servis/";
Document doc = Jsoup.connect(servisURL).get();
Elements jobNode = doc.select("div.jobBox");
Elements headersNode = jobNode.select("h1");
Elements contentNode = jobNode.select("content");
for(int i = 0; i < headersNode.size(); i++){
headersList.add(headersNode.get(i).text());
}
for(int i = 0; i < contentNode.size(); i++){
contentList.add(contentNode.get(i).text());
}
}
}
Hope this may work for you, here i used Asynchronous Task instead of thread
public class MainActivity extends Activity {
String s;
List<String> headersList = new ArrayList<String>();
List<String> contentList = new ArrayList<String>();
ListView listview;
StableArrayAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.listView1);
// threadStart();
// Here i implemented Asynchronous Task instead of Thread
new SampleAsyncTask().execute();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public class SampleAsyncTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(
MainActivity.this);
protected void onPreExecute() {
this.dialog.setMessage("Loading...");
this.dialog.setCancelable(false);
this.dialog.show();
}
#Override
protected Void doInBackground(Void... params) {
try {
webRequest();
adapter = new StableArrayAdapter(MainActivity.this,
android.R.layout.simple_list_item_1, headersList);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
// Here if you wish to do future process for ex. move to another
// activity do here
listview.setAdapter(adapter);
if (dialog.isShowing()) {
dialog.dismiss();
}
}
}
private class StableArrayAdapter extends ArrayAdapter<String> {
HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
public StableArrayAdapter(Context context, int textViewResourceId,
List<String> objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
for (int i = 0; i < objects.size(); ++i) {
mIdMap.put(objects.get(i), i);
}
}
#Override
public long getItemId(int position) {
String item = getItem(position);
return mIdMap.get(item);
}
#Override
public boolean hasStableIds() {
return true;
}
}
public void webRequest() throws Exception {
String servisURL = "http://www.sczg.unizg.hr/student-servis/";
Document doc = Jsoup.connect(servisURL).get();
Elements jobNode = doc.select("div.jobBox");
Elements headersNode = jobNode.select("h1");
Elements contentNode = jobNode.select("content");
for (int i = 0; i < headersNode.size(); i++) {
headersList.add(headersNode.get(i).text());
}
for (int i = 0; i < contentNode.size(); i++) {
contentList.add(contentNode.get(i).text());
}
}
}
At first I propose you to read this guide, especially about Using AsyncTask instead raw Thread.
At second, as I understand, you want to invoke adapterInit from UI thread?
So, you can try this:
runOnUiThread( // <-- method from Activity
new Runnable()
{
#Override
public void run() {
// TODO Auto-generated method stub
adapterInit();
}
}
);
Maybe the problem is that you are not calling the method notifyDataSetChanged() on the adapter to force it to update his informations, it's like notifying the adapter that the underlaying data were updated and that it needs to refresh the associated listview.
You should call it after you fetch the data from the website.
You can use Handler.
In the webRequest thread,When webRequest() finished,you use Handler to notice the main thread to adapterInit().Not use another thread in the webRequest thread.
A simple example.
#Override
public void onClick(DialogInterface dialog,
int which) {
setControlsEnable(false);
new Thread() {
public void run() {
WebserviceMethod wb = new WebserviceMethod();
if (wb.DeleteEmployee(
VerificationUtils
.GetInstance()
.CreateToken(),
personId) == 1) {
Message msg = new Message();
msg.obj = SwitchActivityValue.SWITCH_DELETEPERSON_OK;
mHandler.sendMessage(msg);
}
}.start();
}
#Override
public void handleMessage(Message msg){
super.handleMessage(msg);
SwitchActivityValue value = (SwitchActivityValue)msg.obj;
switch (value) {
case SWITCH_DELETEPERSON_OK:
ManageUtils.EmployeeListDataForAdmin.personInfos.clear();
ManageUtils.EmployeeListDataForAdmin.currentPage = 0;
mActivity.switchActivity(mValue);
break;
case SWITCH_DELETEPERSON_FAILED:
break;
default:
break;
}
mActivity.showMessage(value);
}
Such as the example,you can bind the data in the Handler.When the thread finished,it use hanlder to sendmessage to notice handleMessage handle others.

android html parsing with jsoup

Trying to parse an html pages like http://www.ts.kg/serials/ on android. Tried to do it with htmlcleaner, but it didnot work. Trying to do it with jsoup. In the begining was my code to complex. Here is the shortest code. The same thing works on java Please help. My Logs http://smartpics.kz/imgs/1361209668WW5O.JPG
Here is my class:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] names= {};
String url = "http://www.ts.kg/mults/";
try {
Document doc = Jsoup.connect(url).get();
Element e = doc.body();
Elements ggg = e.getElementsByAttributeValue("class", "categoryblocks");
for (int i =0;i<ggg.size();i++) {
Element linkk = ggg.get(i);
if(linkk.getElementsByTag("a")!=null){
Element atom = linkk.getElementsByTag("a").first();
String n = atom.getElementsByTag("span").first().text();
names[i] = n;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ListView lvMain = (ListView) findViewById(R.id.listViewData);
// создаем адаптер
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, names);
// присваиваем адаптер списку
lvMain.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
posted 20.feb.2013:
tryed to do it as it was proposed by Shoshy (thanks for your answer), but it didn't work (perhaps because of my not-from-right-place-growing hands). Here is my modified code:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
url = "http://www.ts.kg/mults/";
pd = ProgressDialog.show(MainActivity.this, "Working...", "request to server", true, false);
//Запускаем парсинг
new AsyncExecution().execute();
}
private ProgressDialog pd;
String url;;
String names[];
private class AsyncExecution extends AsyncTask<Void, Void, Void>{
#Override
protected Void doInBackground(Void... params) {
// here your task will be done in seperate thread from UI thread
// and if you want to use the variables (that will be modifed here)
// from anywhere in MainActivity, then you should declare them as global
// variable in MainActivity. remember you cannot update UI from here , like
// Toast message. if you want to do that you can use OnPostExecute
// method bellow .
try {
ArrayList<String> array = new ArrayList<String>();
Document doc = Jsoup.connect(url).get();
Element e = doc.body();
Elements ggg = e.getElementsByAttributeValue("class", "categoryblocks");
for (int i =0;i<ggg.size();i++) {
Element linkk = ggg.get(i);
if(linkk.getElementsByTag("a")!=null){
Element atom = linkk.getElementsByTag("a").first();
String n = atom.getElementsByTag("span").first().text();
array.add(n);
}
}
for (int i = 0;i<array.size();i++){
names[i]=array.get(i);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result) {
//Убираем диалог загрузки
pd.dismiss();
//Находим ListView
ListView listview = (ListView) findViewById(R.id.listViewData);
//Загружаем в него результат работы doInBackground
listview.setAdapter(new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_list_item_1, names));
}
}
}
you have to make the request for getting the page in another thread from UI thread. you can use AsyncTask. i am giving some example by editing your code :
the link about AsyncTask is : about AsynckTask
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//the class is defined bellow
new AsyncExecution().execute();
//other codes.....
.......................
}
/// your other codes .....
// you need to add this class
private class AsyncExecution extends AsyncTask<Void, Void, Void>{
#Override
protected Void doInBackground(Void... params) {
// here your task will be done in seperate thread from UI thread
// and if you want to use the variables (that will be modifed here)
// from anywhere in MainActivity, then you should declare them as global
// variable in MainActivity. remember you cannot update UI from here , like
// Toast message. if you want to do that you can use OnPostExecute
// method bellow .
try {
Document doc = Jsoup.connect(url).get();
Element e = doc.body();
Elements ggg = e.getElementsByAttributeValue("class", "categoryblocks");
for (int i =0;i<ggg.size();i++) {
Element linkk = ggg.get(i);
if(linkk.getElementsByTag("a")!=null){
Element atom = linkk.getElementsByTag("a").first();
String n = atom.getElementsByTag("span").first().text();
names[i] = n;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
protected void onPostExecute(Void result) {
}
}

Load data from json to list view

I have an application which load data from json to android as below
public class MainActivity extends Activity {
private final String URL_SERVICE = "http://92.253.101.239:81/sudandoctors/api.aspx?op=5&GovernorateId=&SpecializationId=&DoctorName=&LastDoctorId=0";
private final String URL_IMAGE_BASE = "http://92.253.101.239:81/sudandoctors/UploadedFiles/";
TextView tv;
DoctorInfo doctorObj = new DoctorInfo();
ArrayList<DoctorInfo> doctorsInfoList = new ArrayList<DoctorInfo>();
ListView lv = (ListView)findViewById(R.id.mylist);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AsyncHttpClient client = new AsyncHttpClient();
client.get(URL_SERVICE, new AsyncHttpResponseHandler() {
#Override
public void onStart() {
super.onStart();
// show loading bar
Log.d("onStart", "onStart");
}
#Override
public void onSuccess(String response) {
super.onSuccess(response);
Log.d("onSuccess", "onSuccess");
DoctorsModel doctorModel = new DoctorsModel();
ArrayList<DoctorInfo> doctorsInfoList = new ArrayList<DoctorInfo>();
try {
// convert response to JSON
JSONObject json = new JSONObject(response);
// get JSON Items
doctorModel.setDoctorCnt(json.getInt("DoctorsCount"));
doctorModel.setOp(json.getString("op"));
JSONArray doctorsArray = json.getJSONArray("Doctors");
Log.d("dr arrat", doctorsArray.toString());
for (int i = 0; i < doctorsArray.length(); i++) {
JSONObject doctorJSON = doctorsArray.getJSONObject(i);
doctorObj .setId(doctorJSON.getString("Id"));
Log.d("id", doctorJSON.getString("Id"));
doctorObj.setName(doctorJSON.getString("DoctorName"));
doctorObj.setGovernorateId(doctorJSON.getString("GovernorateId"));
doctorObj.setGovernorateName(doctorJSON.getString("GovernorateName"));
doctorObj.setSpecializationName(doctorJSON.getString("SpecializationName"));
doctorObj.setHospitalId(doctorJSON.getString("HospitalId"));
doctorObj.setHospitalName(doctorJSON.getString("HospitalName"));
doctorObj.setImageName(URL_IMAGE_BASE + doctorJSON.getString("ImageName"));
doctorObj.setMobile(doctorJSON.getString("Mobile"));
doctorObj.setSpecializationId(doctorJSON.getString("SpecializationId"));
doctorObj.setWeekendDays(doctorJSON.getString("WeekendDays"));
doctorObj.setWorkingDays(doctorJSON.getString("WorkingDays"));
doctorObj.setWorkingTime(doctorJSON.getString("WorkingTime"));
doctorsInfoList.add(doctorObj);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onFailure(Throwable e, String message) {
super.onFailure(e, message);
// show error message
}
#Override
public void onFinish() {
super.onFinish();
// remove loading bar
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.activity_list_item);
// Assign adapter to ListView
lv.setAdapter(adapter);
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
And I want to show the data in list view, how can I do that ?
Use an Adapter - http://developer.android.com/reference/android/widget/Adapter.html
Create an adapter with your data, then set that adapter as the ListView's adapter.

Categories

Resources