List_item.xml
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large
Text"
android:textColor="#0000ff"
android:background="#00ffff"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
MainActivity.java
package
com.sattar.listviewexample;
import
android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import
android.widget.ArrayAdapter;
import
android.widget.ListView;
import
android.widget.Toast;
public class MainActivity extends ListActivity {
//DataSource.................
private String []osData={"Linux","Windos
7","Windos
8","Mac osx","Dos oS","Solaric","Mozila
oS","Vista","Windos
Xp"};
//Adapter.....................
ArrayAdapter<String>adapter;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
adapter=new
ArrayAdapter<String>(this,R.layout.list_item, R.id.textView1, osData);
setListAdapter(adapter);
}
@Override
protected void
onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l,
v, position, id);
Toast.makeText(getApplicationContext(),
"item
Index"+position+"item Name"+osData[position], Toast.LENGTH_LONG).show();
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the
menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Activity_main.xml
(ফাকা)
Thanks Everybody.
No comments:
Post a Comment