Android Open Source - CSVListExample Main Activity






From Project

Back to project page CSVListExample.

License

The source code is released under:

Apache License

If you think the Android project CSVListExample 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.makemyandroidapp.example.csvlist;
//www  .  j a  va2  s. c  o m
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

/*
 * Very basic Activity, the only things it does
 * are get the ListView reference from our layout.
 * Create an Adapter, set the Adapter to the ListView
 * and handle the onItemClick events for when the user
 * clicks on a row.
 */
public class MainActivity extends Activity {

  CSVAdapter mAdapter;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    //Lookup our ListView
    ListView mList = (ListView)findViewById(R.id.mList);
    
    //Create Adapter. The second parameter is required by ArrayAdapter
    //which our Adapter extends. In this example though it is unused,
    //so we'll pass it a "dummy" value of -1.
    mAdapter = new CSVAdapter(this, -1);
    
    //attach our Adapter to the ListView. This will populate all of the rows.
    mList.setAdapter(mAdapter);
    
    
    /*
     * This listener will get a callback whenever the user clicks on a row. 
     * The pos parameter will tell us which row got clicked.
     * 
     * For now we'll just show a Toast with the state capital for the state that was clicked.
     */
    mList.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View v, int pos,long id) {
        Toast.makeText(v.getContext(), mAdapter.getItem(pos).getCapital(), Toast.LENGTH_SHORT).show();
      }
    });
  }
}




Java Source Code List

com.makemyandroidapp.example.csvlist.CSVAdapter.java
com.makemyandroidapp.example.csvlist.MainActivity.java
com.makemyandroidapp.example.csvlist.State.java