Monday, October 22, 2012

Android List View ( Simple ListView using ArrayAdapter)


In java file( .java)


package ListView_Pkge.app;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListView_Acty extends ListActivity {

String[] Qitems = {
"Q1:What are the advantages of Object Oriented Programming Languages (OOPL)?",
"Q2:How do you express an ‘is a’ relationship and a ‘has a’ relationship or explain inheritance and composition? What is the difference between composition and aggregation?",
"Q3:What do you mean by polymorphism, inheritance, encapsulation, and dynamic binding?",
"Q4:What is the difference between an abstract class and an interface and when should you use them?",
"Q5:How would you communicate between applets and servlets?",
"Q6:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q7:Explain the RMI architecture?",
"Q8:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q9:How will you pass parameters in RMI?",
"Q10:What is the difference between final, finally and finalize() in Java?",
"Q11:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q12:Explain the RMI architecture?",
"Q13:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q14:How will you pass parameters in RMI?",
"Q15:What is the difference between final, finally and finalize() in Java?"};

String[] Aitems = {  "Ans1","Ans2","Ans3","Ans4","Ans5","Ans6","Ans7","Ans8","Ans9","Ans10","Ans11","Ans12","Ans13","Ans14","Ans15"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.listview2);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Qitems));
}

public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this, Aitems[position], Toast.LENGTH_LONG).show();
}
}


In XML file ( .xml)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
</LinearLayout>


Note :- Question and Answers in String Qitem and Aitems are just for example.
Source Code




No comments:

Post a Comment