I am trying to get from one screen to another ( I can do so sucessfully but its not the right screen)
Code
AdapterView.OnItemClickListener classListListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(id == 1){
Toast.makeText(getApplicationContext(),"1",Toast.LENGTH_SHORT).show();
Intent i = new Intent(QuestionBankListActivity.this, Questions.class);
startActivity(i);
finish();
}
}
this portion of my code gets me to my Questions.class which is what I need, but my issue is here
class Questions extends AppCompatActivity, and I need extends to ListView
Code
public class Questions extends AppCompatActivity {
private QuestionBankDB qbdb = null;
private ListView questionsListView;
private CursorAdapter questionsListViewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
qbdb = new QuestionBankDB();
new questionListTask().execute((Object[]) null);
}
}
However if I change extends ListView, even with nothing besides onCreate in the class, when I run the app it crashes when i get to that point of the app (when its supposed to pull up the UI for questions)
but if I keep it at extends AppCompatActivity with just onCreate it goes to that screen fine with no error.
The reason I cannot keep it in extends AppCompatActivity is because my code needs list view
Code
package edu.davenport.cisp340.studentdbprototype;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class Questions extends AppCompatActivity {
private QuestionBankDB qbdb = null;
private ListView questionsListView;
private CursorAdapter questionsListViewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
qbdb = new QuestionBankDB();
new questionListTask().execute((Object[]) null);
}
private class questionListTask extends AsyncTask<Object, Object, Cursor>
{
@Override
protected Cursor doInBackground(Object... params)
{
return qbdb.Questions();
}
@Override
protected void onProgressUpdate(Object... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(Cursor cursor) {
super.onPostExecute(cursor);
questionsListView = getListView();
questionsListView.setOnItemClickListener(questionsListListener);
// map to on resume
String[] map_from = new String[]{"QUESTION_TEXT"};
int[] map_to = new int[]{R.id.txtQuestions};
questionsListViewAdapter = new SimpleCursorAdapter(Questions.this, R.layout.content_questions, cursor, map_from, map_to);
setListAdapter(questionsListViewAdapter);
}
} // end StudentListTask
AdapterView.OnItemClickListener questionsListListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
};
}
getListView; and SetListAdapter are red cannot resolve method..
I also tried doing this
Code
public class Questions extends AppCompatActivity {
private QuestionBankDB qbdb = null;
private ListView questionsListView;
private CursorAdapter questionsListViewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
{
questionsListView = (ListView) findViewById(R.id.listView);
CursorAdapter questionlistAdapter = new CursorAdapter();
questionsListView.setAdapter(questionlistAdapter);
}
qbdb = new QuestionBankDB();
new questionListTask().execute((Object[]) null);
but gives me an error on
CursorAdapter questionListAdapter = new CursorAdapter();
saying it is abstract and cannot be instantaited