Created
February 5, 2017 14:38
-
-
Save imjeevandeshmukh/612486145dd803a062b0e755490d41a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bytelogs.listviewexample; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.ArrayAdapter; | |
import android.widget.ListView; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ListView listView = (ListView)findViewById(R.id.monthlistView);//declare listView | |
ArrayAdapter monthsarray = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,R.array.months);//create arrayadapter | |
listView.setAdapter(monthsarray);//setting arrayadapter to listView | |
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { | |
String value = (String)adapterView.getItemAtPosition(i); //make nitemClick listener | |
Toast.makeText(getBaseContext(), value,Toast.LENGTH_LONG).show(); //on item clicked make toast meassage | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment