How to create a listview for displaying the data in android?
<p>In I am working on quiz application. In my project after the test is over I need to keep <strong>review button</strong>. <strong>When review button is clicked all the questions which appeared for test has to be displayed again with correct answer one color ,wrong answer one color and timeout answer other color.</strong> So I kept all the questions,answers and selected answer in an arraylist. <strong>Now in review page I need to display the question,options and explanation in a listview.</strong> Hence for that I have created a listview. But it showing null pointer exception. </p>

<p>Mycode:</p>

<p>public class testreview extends Activity {</p>

<pre><code>private ListView listViewScore = null;
private ListViewAdapter listViewAdapter = null;
public static ArrayList&lt;ArrayList&lt;String&gt;&gt; ourstringList1 = Select.stringList1;
    private ArrayList&lt;ArrayList&lt;String&gt;&gt; usernameArrLst = ourstringList1;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list);
    listViewScore=(ListView)findViewById(R.id.list);
    usernameArrLst = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
    listViewAdapter = new ListViewAdapter();
    listViewScore.setAdapter(listViewAdapter);
}

class ListViewAdapter extends BaseAdapter{

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if(usernameArrLst==null){
            return 0;
        }

        return usernameArrLst.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return usernameArrLst.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        // TODO Auto-generated method stub
        View rowView=view;
        if(rowView==null){
            LayoutInflater layoutinflate =LayoutInflater.from(testreview.this);
            rowView=layoutinflate.inflate(R.layout.listrow, parent, false);
        }

        TextView textViewName=(TextView)rowView.findViewById(R.id.tv_case);
        textViewName.setText((CharSequence) usernameArrLst.get(position));

        return rowView;
    }

}
</code></pre>

<p>}</p>
