ListView tutorial point mathi karvu
//activity_main.xml <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/listView"> </ListView>
//string.xml <resources> <string name="app_name">ListView</string> <string-array name="array_technology"> <item>Android</item> <item>Java</item> <item>Php</item> <item>Hadoop</item> <item>Sap</item> <item>Python</item> <item>Ajax</item> <item>C++</item> <item>Ruby</item> <item>Rails</item> <item>.Net</item> <item>Perl</item> </string-array> </resources>//MainActivity.java public class MainActivity extends AppCompatActivity { ListView listView; String[] listItem; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView=(ListView)findViewById(R.id.listView); listItem = getResources().getStringArray(R.array.array_technology); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, listItem); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // TODO Auto-generated method stub String value=adapter.getItem(position); Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show(); } }); } }
Comments
Post a Comment