Posted by Shoaib at 9:34:00 pm
Read our previous post
Main Activity:
package com.example.shoaibm.praclist; import android.content.res.Resources; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends ActionBarActivity { ListView listView; String[] data; Resources res; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView)findViewById(R.id.listView); res = getResources(); data = res.getStringArray(R.array.teacher); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(),data[position],Toast.LENGTH_LONG ).show(); } }); }
Activity Main:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/listView" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentBottom="true" android:layout_alignParentTop="true" /> </RelativeLayout>Values/Strings.xml:<resources> <string name="app_name">PracList</string> <string name="hello_world">Hello world!</string> <string name="action_settings">Settings</string> <string-array name="teacher"> <item> C</item> <item> C++</item> <item> Java</item> <item> Python</item> <item> SHoaib</item> <item> Mahmud</item> <item> Jibon</item> <item> Linkon</item> <item> C</item> <item> C++</item> <item> Java</item> <item> Python</item> <item> SHoaib</item> <item> Mahmud</item> <item> Jibon</item> <item> Linkon</item> </string-array> </resources>Developer Notes: For better Understanding:
No comments:
Post a Comment