Android Open Source - firstcodeandroid Main Activity






From Project

Back to project page firstcodeandroid.

License

The source code is released under:

MIT License

If you think the Android project firstcodeandroid 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

package com.vjia.hellonote;
/* ww  w . j  av a  2  s  . co  m*/
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity implements OnClickListener {

  private Button textbtn, imgbtn, videobtn;
  private ListView lv;
  private Intent i;
  private MyAdapter adapter;
  private NotesDB notesDB;
  private SQLiteDatabase dbReader;
  private Cursor cursor;

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

  public void initView() {
    lv = (ListView) findViewById(R.id.list);
    textbtn = (Button) findViewById(R.id.text);
    imgbtn = (Button) findViewById(R.id.img);
    videobtn = (Button) findViewById(R.id.video);
    textbtn.setOnClickListener(this);
    imgbtn.setOnClickListener(this);
    videobtn.setOnClickListener(this);
    notesDB = new NotesDB(this);
    dbReader = notesDB.getReadableDatabase();
    lv.setOnItemClickListener(new OnItemClickListener() {

      @Override
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        cursor.moveToPosition(position);
        Intent i = new Intent(MainActivity.this, SelectAct.class);
        i.putExtra(NotesDB.ID,
            cursor.getInt(cursor.getColumnIndex(NotesDB.ID)));
        i.putExtra(NotesDB.CONTENT, cursor.getString(cursor
            .getColumnIndex(NotesDB.CONTENT)));
        i.putExtra(NotesDB.TIME,
            cursor.getString(cursor.getColumnIndex(NotesDB.TIME)));
        i.putExtra(NotesDB.PATH,
            cursor.getString(cursor.getColumnIndex(NotesDB.PATH)));
        i.putExtra(NotesDB.VIDEO,
            cursor.getString(cursor.getColumnIndex(NotesDB.VIDEO)));
        startActivity(i);
      }
    });
  }

  @Override
  public void onClick(View v) {
    i = new Intent(this, AddContent.class);
    switch (v.getId()) {
    case R.id.text:
      i.putExtra("flag", "1");
      startActivity(i);
      break;

    case R.id.img:
      i.putExtra("flag", "2");
      startActivity(i);
      break;

    case R.id.video:
      i.putExtra("flag", "3");
      startActivity(i);
      break;
    }
  }

  public void selectDB() {
    cursor = dbReader.query(NotesDB.TABLE_NAME, null, null, null, null,
        null, null);
    adapter = new MyAdapter(this, cursor);
    lv.setAdapter(adapter);
  }

  @Override
  protected void onResume() {
    super.onResume();
    selectDB();
  }

}




Java Source Code List

com.example.activitylifecycletest.DialogActivity.java
com.example.activitylifecycletest.MainActivity.java
com.example.activitylifecycletest.NormalActivity.java
com.example.activitytest.FirstActivity.java
com.example.listviewtest.FruitAdapter.java
com.example.listviewtest.Fruit.java
com.example.listviewtest.MainActivity.java
com.jikexueyuan.counttime.MainActivity.java
com.jikexueyuan.getmyphonenumber.GetNumber.java
com.jikexueyuan.getmyphonenumber.MainActivity.java
com.jikexueyuan.getmyphonenumber.MyAdapter.java
com.jikexueyuan.getmyphonenumber.PhoneInfo.java
com.vjia.bookcollector.MainActivity.java
com.vjia.coolweather.MainActivity.java
com.vjia.coolweather.activity.ChooseAreaActivity.java
com.vjia.coolweather.activity.WeatherActivity.java
com.vjia.coolweather.db.CoolWeatherDB.java
com.vjia.coolweather.db.CoolWeatherOpenHelper.java
com.vjia.coolweather.model.City.java
com.vjia.coolweather.model.County.java
com.vjia.coolweather.model.Province.java
com.vjia.coolweather.util.HttpCallbackListener.java
com.vjia.coolweather.util.HttpUtil.java
com.vjia.coolweather.util.Utility.java
com.vjia.helloandroid.FirstActivity.java
com.vjia.helloandroid.HelloAndroidActivity.java
com.vjia.hellonote.AddContent.java
com.vjia.hellonote.MainActivity.java
com.vjia.hellonote.MyAdapter.java
com.vjia.hellonote.NotesDB.java
com.vjia.hellonote.SelectAct.java
com.vjia.jokeking.GetJoke.java
com.vjia.jokeking.HttpCallbackListener.java
com.vjia.jokeking.HttpUtil.java
com.vjia.jokeking.Joke.java
com.vjia.jokeking.MainActivity.java
com.vjia.jokeking.MyAdapter.java
com.vjia.locationtest.MainActivity.java