Question

I'm trying to do a ListView and I know my AsyncTask is being run via a log file but the actual Adapter class isn't being called, because I have a log in there too and it's not showing.

@Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);

          TaskAdapter adapter = new TaskAdapter(ToDoList.this, R.layout.item_task, tasks);
          setListAdapter(adapter);

          Log.d("demo", "onPostExecute ACCESSED");

      }

TaskAdapter.java

public class TaskAdapter extends ArrayAdapter<Task>{

private Context context;
private List<Task> objects;

public TaskAdapter(Context context, int resource, List<Task> objects) {
    super(context, resource, objects);
    this.context = context;
    this.objects = objects;
    }

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    Task task = objects.get(position);

    LayoutInflater inflater = 
            (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.item_task, null);

    // Get Text Views
    TextView tv_title = (TextView) view.findViewById(R.id.task_title);
    TextView tv_item = (TextView) view.findViewById(R.id.task_item);

    tv_title.setText(task.getTitle());
    tv_item.setText(task.getItem());

    Log.d("demo", "ADAPTER ACCESSED");

    return view;
    }


}

activity_to_do_list.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.geotasker.ToDoList"
tools:ignore="MergeRootFrame" >

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="To Do List Here"
    android:textAppearance="?android:attr/textAppearanceLarge" />

    <ListView
    android:id="@+id/android:list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</FrameLayout>

ToDoList (My Activity)

public class ToDoList extends ListActivity {

private ActionBarActivity abarAct;

// Needed stuff for getting Tasks list and creating ListView
DataManager dm;
ArrayList<Task> tasks;
Task task;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_to_do_list);
    abarAct = new ActionBarActivity();

//      if (savedInstanceState == null) {
//          abarAct.getSupportFragmentManager().beginTransaction()
//                  .add(R.id.container, new PlaceholderFragment()).commit();
//      }

    tasks = new ArrayList<Task>();
    task = new Task();
    dm = new DataManager(this);

//      TextView tv = (TextView) findViewById(R.id.textView1);
//      tv.setText(tasks.get(0).getTitle());

    new GetGeoTasks().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.to_do_list, 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);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_to_do_list,
                container, false);
        return rootView;
    }
}


// If any errors occur, then make a method to first check the db for tasks, then execute AsyncTask

// AsyncTask to get GeoTasks
  private class GetGeoTasks extends AsyncTask<Void, Void, Void> {

      @Override
      protected Void doInBackground(Void... params) {

          tasks = dm.getAllTasks();
          Log.d("demo", "doInBackground ACCESSED");

          return null;
      }

      @Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);

          TaskAdapter adapter = new TaskAdapter(ToDoList.this, R.layout.item_task, tasks);
          setListAdapter(adapter);

          Log.d("demo", "onPostExecute ACCESSED");

      }

      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }


  } // END GetGeoTasks


}

Can anyone help point me in the right direction? Thanks.

Was it helpful?

Solution

Try add

adapter.notifyDataSetChanged();

below setListAdapter(Adapter);

hope this helped you =)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top