Skip to content

Instantly share code, notes, and snippets.

@edenizk
Created July 28, 2018 12:55
Show Gist options
  • Save edenizk/ea766d253c51b0494205e31273e2a4d1 to your computer and use it in GitHub Desktop.
Save edenizk/ea766d253c51b0494205e31273e2a4d1 to your computer and use it in GitHub Desktop.
List View App
package com.example.deniz.listviewapp;
import android.app.ListActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends ListActivity implements AdapterView.OnItemClickListener {
String[] courseNames = {"Android Developer Course", "iOS Developer Course", "Java Developer Course",
"Objective-C Developer Course", "Web Developer Course"};
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new ArrayAdapter<String>(MainActivity.this, R.layout.activity_main, courseNames);
setListAdapter(adapter);
ListView listView = getListView();
listView.setOnItemClickListener(MainActivity.this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String itemValue = parent.getItemAtPosition(position).toString();
Toast.makeText(MainActivity.this, itemValue, Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment