Android Open Source - AndroidSqliteMultichoiceExample Main Activity






From Project

Back to project page AndroidSqliteMultichoiceExample.

License

The source code is released under:

Apache License

If you think the Android project AndroidSqliteMultichoiceExample listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright 2014 Yehezkel (Zack) Yovel/*from w  w w. ja va2  s  . c om*/
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package zack.examples.questiondb;

import java.util.List;

import zack.examples.questiondb.database.DataAccessObject;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.TextView;

public class MainActivity extends Activity implements OnItemClickListener {

  public static final String EXTRA_SUBJECT = "zack.examples.questiondb.EXTRA_SUBJECT";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PopulateSubjectGridTask subjectTask = new PopulateSubjectGridTask();
    subjectTask.execute((Void) null);
  }

  private class PopulateSubjectGridTask extends
      AsyncTask<Void, Void, List<String>> {

    @Override
    protected List<String> doInBackground(Void... params) {
      DataAccessObject dao = DataAccessObject
          .getInstance(MainActivity.this);
      List<String> subjects = dao.getSubjectList();
      return subjects;
    }

    @Override
    protected void onPostExecute(List<String> result) {
      GridView gridView = (GridView) findViewById(R.id.gridView1);
      ListAdapter adapter = new ArrayAdapter<String>(MainActivity.this,
          R.layout.grid_item, R.id.gritTextView, result);
      gridView.setAdapter(adapter);
      gridView.setOnItemClickListener(MainActivity.this);
    }

  }

  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position,
      long id) {
    Intent intent = new Intent(this, QuestionsActivity.class);
    TextView textView = (TextView) view.findViewById(R.id.gritTextView);
    intent.putExtra(EXTRA_SUBJECT, textView.getText());
    startActivity(intent);
  }
}




Java Source Code List

zack.examples.questiondb.MainActivity.java
zack.examples.questiondb.QuestionsActivity.java
zack.examples.questiondb.database.DBContract.java
zack.examples.questiondb.database.DataAccessObject.java
zack.examples.questiondb.database.QuestionsOpenHelper.java
zack.examples.qustiondb.entities.Question.java